#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
Copyright Pascal KREZEL Janvier 2012

pascal.krezel@gmail.com

TUBA : langage de modélisation sous SaloméMéca.

Ce logiciel est régi par la licence CeCILL soumise au droit français et
respectant les principes de diffusion des logiciels libres. Vous pouvez
utiliser, modifier et/ou redistribuer ce programme sous les conditions
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA 
sur le site "http://www.cecill.info".

En contrepartie de l'accessibilité au code source et des droits de copie,
de modification et de redistribution accordés par cette licence, il n'est
offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons,
seule une responsabilité restreinte pèse sur l'auteur du programme,  le
titulaire des droits patrimoniaux et les concédants successifs.

A cet égard  l'attention de l'utilisateur est attirée sur les risques
associés au chargement,  à l'utilisation,  à la modification et/ou au
développement et à la reproduction du logiciel par l'utilisateur étant 
donné sa spécificité de logiciel libre, qui peut le rendre complexe à 
manipuler et qui le réserve donc à des développeurs et des professionnels
avertis possédant  des  connaissances  informatiques approfondies.  Les
utilisateurs sont donc invités à charger  et  tester  l'adéquation  duInd1
logiciel à leurs besoins dans des conditions permettant d'assurer la
sécurité de leurs systèmes et ou de leurs données et, plus généralement, 
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. 

Le fait que vous puissiez accéder à cet en-tête signifie que vous avez 
pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.





Travaux à réaliser par ordre de priorité:
--------------------------------------------------------------------------------
Les ressorts ne peuvent pas être utilisé pour le moment en flexibilité
Vérifier la cohérence entre le type de calcul demandé et les commandes utilisées.
Vérifier que la commande Calcul est bien à la fin du fichier.
Test du premier Si après un commande Model
Créer une commande Fnd : Force nodale dihédrique
Créer une commande Pr : Point relatif
Mettre un Ci nommé entre un VPx et un VcPx
Créer la commande Vd2xOpp pour obtenir le vecteur opposé à Vd2x
Création automatique de piquage en fonction des longueurs / intersection.
    
    
"""

import sys
import os
import math
from TUBA_fonctions import *
from TUBA_VerifierCode import *

try:
    from TUBA_Sections import LesSections
except:
    print(" TUBA_Sections inconnu !")
    pass


# FICHIERS
MonRepertoire =  os.getcwd()
TubaRepertoire = os.environ["TUBA"]
nom = sys.argv[1]
fichier_pkl = MonRepertoire + "/"+ nom + ".pkl"
fichier_py = MonRepertoire + "/"+ nom + ".x.py"
fichier_comm = MonRepertoire + "/"+ nom + ".x.comm"



#-------------------------------------------------------------------------------
def AAA_Constantes():
    pass
eps=1E-10
    
# Coefficients pour la représentation volumique d'un piquage avec Piq
Kpiq_c=1.5            
Kpiq_p=1.5

KVpiq_c=1.2            # Coefficients pour la représentation volumique d'un piquage
KVpiq_p=1.2



doc1=1                      # Pour afficher les titres
doc2=1                      # Pour afficher les sous-titres
doc3=1                      # Pour vérifier toutes les étapes
doc4=0                      # Pour vérifier toutes les fonctions


#-------------------------------------------------------------------------------
def AAA_Materiaux():
    pass
# Dico des matériaux prédéfinis (! : mettre le nom en MAJUSCULE!)
#                    E       nu      rho     alpha   lamb    rhoCp
DicMat={  
"ACIER":	[   210,    0.3,    7.8,    10.0,   50.0,   4.0    	], #Valeurs simplifiées
"RIGIDE":	[   20000,  0.3,    0.0,    10.9,   54.6,   3.71    	],
"IMS":	    [   206,    0.29,   7.8,    10.9,   54.6,   3.71    	],
"A42":	    [   204,    0.4,    7.8,    10.9,   54.6,   3.71    	],
"Ax1":      [   165.8,  0.3,    13.404, 12.88,  54.6,   3.71    	],
}

#-------------------------------------------------------------------------------
def AAA_String():
    pass
Ind1=" "*8                 # Indentations
Ind2=" "*16
Ind3=" "*24
Ind4=" "*32
Ind5=" "*40
#Autres
x="x"
O="0"


#-------------------------------------------------------------------------------
def AAA_Couleurs():
    pass
Couleur={
    "Bloc":"1,1,0",              
    "TUBE":"0.8,0.8,0.8",
    "BARRE":"0.8,0.8,0.8",
    "CABLE":"0.8,0.8,0.8",
    "TUYAU":"0.8,0.8,0.8",
    "RESSORT":"1.0,1.0,0.0",
    "Bute": "0,1,1" ,           
    "3D":"0.5,0.8,0.8",        
    "Bride":"1,0.6,0",
    "Rigide":"0.3,0.3,0.3",
    "Masse":"0,0,1",
    "Vanne":"1,0,0",
    "Piq":"0.9,0.9,0.9",
    "Support":{     "PF":["0.666,0,0","0.666,0,0"], 
	                "CB":["1,1,0","0.666,0,0"], 
	                "GL":["1,1,0","1,1,0"]
	                }
    }






#-------------------------------------------------------------------------------
def AAA_Listes_de_commandes():
    pass

	        
#Liste des commandes géométriques élémentaire utilisées dans TraiterCode:              
LesCdGeo=[
                "Ca",
                "Sc",
                "P","Px","Pxvr",
                "V"   
                ]             
                
#Liste des commandes à traiter uniquement dans ConvertirCode_2:
LesCdConver2=[  
                "Ci",
                ]



#-------------------------------------------------------------------------------
def AAA_Listes_de_composantes_XYZ():
    pass
DDL = [ 
        "DX","DY","DZ",
        "DRX","DRY","DRZ",
#Les composantes suivantes ne sont pas encore gérées en local
#        "W0","WI1","WO1",
#        "UI2","VI2","WI2","UO2","VO2","WO2",
#        "UI3","VI3","WI3","UO3","VO3","WO3",
#        "UI4","VI4","WI4","UO4","VO4","WO4",
#        "UI5","VI5","WI5","UO5","VO5","WO5",
#        "UI6","VI6","WI6","UO6","VO6","WO6",
        ]
FORCE = ["FX","FY","FZ"]
MOMENT= ["MX","MY","MZ"]



#-------------------------------------------------------------------------------
def AAA_Dictionnaire_materiaux():
    pass


#Autres
x="x"
O="0"

#Lites de modèle
LesModeles_ROND=[
    "TUBE",
    "3D",
    "CABLE",
    "BARRE",
    "TUYAU3M",
    "TUYAU6M",
    "RESSORT"
    ]
    
LesWires=["Face","FaceVc","Wire","WireVc","Wire2D","Wire2Dc","Wire2Ds"]


#-------------------------------------------------------------------------------
class Test:



    #---------------------------------------------------------------------------
    # Compteurs
    #---------------------------------------------------------------------------
    nP = -1
    nDDL = 0
   

    #---------------------------------------------------------------------------
    Ni=40                       # Nombre de tiret pour les séparateurs
    #---------------------------------------------------------------------------
    forme= "CERCLE"             # Forme de la section de TUBE
    model="TUYAU3M"             # type d'élément utilisé
    repere="LOCAL"
    iQUAD=False                 # type de maillage : quadratique ou linéaire
    forme="ROND"
    iDebutTUYAU=False           # Indicateur de debut pour les TUYAU
    iModel=False                # Indicateur de la présence de Model
    iRed_Force_Repartie=False
    iWire2Dsym=False             # Indicateur d'un Wire2D symétrique
    
    #---------------------------------------------------------------------------    
    # Indicateur du type de calcul
    #---------------------------------------------------------------------------
    iCalc_Flex=False                 # Indicateur d'un calcul de flexibilité
    iCalc_Dynamique=False
    iWireVc=False
    
    #---------------------------------------------------------------------------    
    # Contenu
    #---------------------------------------------------------------------------
    iRhoV=False                 # Indicateur de prise en compte du poids du contenue
    RhoV=0                      # Densité du contenu par défaut

    #---------------------------------------------------------------------------    
    # Temperature
    #---------------------------------------------------------------------------    
    iTemp=False                 # Indicateur de présence de la commande T imposant un chanmp de température
    Temp=0                      # Température
    LesVs_iTemp =[]             # Liste des éléments de même température (i pour identique)
    
    #---------------------------------------------------------------------------     
    # Pression
    #---------------------------------------------------------------------------
    iPress=False          
    Press=0
    LesVs_iPress =[]     
    
    #---------------------------------------------------------------------------     
    # Matériaux
    #---------------------------------------------------------------------------     
    LesVs_iMat =[]              # Liste des Maille de même matière (i pour identique)
    
    #---------------------------------------------------------------------------     
    # Réducteur
    #---------------------------------------------------------------------------
    iRed=False                  # Indicateur de présence de réducteur

    #---------------------------------------------------------------------------
    # Codes
    #---------------------------------------------------------------------------
    CodeS=[]                    # Code Python dans Salomé
    CodeA=[]                    # Code ASTER
    CodeP=[]                    # Code TUBA 
    Calcul=""                   # Nom du calcul réalisé

    #---------------------------------------------------------------------------
    # Efforts
    #---------------------------------------------------------------------------
    LesForces=[]                # Liste des forces 
    LesMoments=[]               # Liste des moments
    
    
    #---------------------------------------------------------------------------
    # Ressort
    #--------------------------------------------------------------------------- 
    raideur=0 
    LesRESSORTs=[]
     
    #---------------------------------------------------------------------------
    # Poutre
    #---------------------------------------------------------------------------  
    angleP=0                    # Angle de rotation de l'axe principale de la    
                                # section autour de la direction de la fibre neutre
    Section=[]
    
    #---------------------------------------------------------------------------
    # Supports
    #---------------------------------------------------------------------------  
    LesBi=[]                    # Liste des butées 1D symétriques 
    LesSupports=[]              # Liste des supports 
    Supportx=""                 # Support courant
    
    #---------------------------------------------------------------------------
    # Maillage
    #---------------------------------------------------------------------------  
    NbElement=8                 # Noombre d'éléments sur un segment
    LgElement=10                # Longueur d'un élément
    
    LesCd = []                  # Liste de toutes les commandes     
    LTout=[]

    Secx=[]
    LVar=[]                     # Liste des variables définies avec Var
    LVarB=[]                    # Liste des variables définies dans les boucles
    LDDL=[]                     # Liste des types de blocages utilisés
    
    LesTUBEs=[]                 # Liste des Maille de type TUBE
    Les3Ds=[]
    LesCABLEs=[]                # Liste des Maille de type CABLE
    LesBARREs=[]                # Liste des Maille de type BARRE
    LesTUYAU3Ms=[]              # Liste des Maille de type TUYAU3M
    LesTUYAU6Ms=[]              # Liste des Maille de type TUYAU6M
    LesMasses=[]                # Liste des points devant faire l'objet d'un CreaPoint pour affecter une masse.
    LesLis=[]                   # Liste des Mailles comme liaison solide.
    LesRigides=[]               # Liste des mailles faites avec des matériaux rigides.
    LesRONDs_iSec=[]            # Liste des mailles de section Ronde
    LesRONDx4s_iSec=[]          # Liste des mailles de section Ronde pour les Vannes et les brides
    
    LesPOUTREs=[]               # Les éléments POUTRE qui ne sont pas de section ronde
    LesRECTs_iSec=[]            # de même section
    LesPOUTREs_iSec=[]

    #---------------------------------------------------------------------------
    DicP={}                     # Dictionnaire d'info sur les points créés.

    #---------------------------------------------------------------------------
    LVx=0                       # Longueur de vecteur courant
    iCodeS=0                    # Indice de ligne dans CodeS
    iCodeP=0
    ICodeP=0                    # Nombre de ligne dans CodeP à traiter
    
    #---------------------------------------------------------------------------
    Vd1x0 = [0,0,1]             # Vecteur d'orientation dihédrique par défaut
    Vd2x0 = [1,0,0]             # Vecteur d'orientation dihédrique par défaut 
    Vd1x=Vd1x0
    Vd2x=Vd2x0
    VPx=[0,0,0]                 # Vecteur coordonnées du point courant
    ad1x = 0                    # Angle dihédriques courants (utilisés par Ci)
    ad2x = 0                    # Angle dihédriques courants (utilisés par Ci)
    Px=""                       # Point Courant
    Pn=""                       # Nouveau point
    LastCd =""                  # Nom de la commande précédente

    Vg=[0,0,-9.8]               # Vecteur accélération gravitationnelle (m/s²)

    Repere="LOCAL"              # Type de repère pour les supports    

    SIF=1                       # coefficient d'amplification de contrainte avec fatigues
    Kunite=1
    freqMax=1000
    Matx="ACIER"


    #---------------------------------------------------------------------------
    def AddLesBi(self,A,nom,Bi):
        if nom !="":
            P=nom
        else:
            P=self.Px
        self.LesBi.append([A,P,Bi]) 


    #---------------------------------------------------------------------------
    def AddLesSupp(self,Typ,A,nom,sec,modelo,repere,Cd0):
        self.LesSupports.append([Typ,A,nom,sec,modelo,repere,Cd0])


    #---------------------------------------------------------------------------
    def Ajouter_AngleP(self,A,nom,lien):
        self.angleP=float(A[0])


    #---------------------------------------------------------------------------
    def Ajouter_Bud(self,A,nom,lien):

        [R,e]=self.Secx
        [d,ad]=ConvNFloat(A,1)
        
        Px0=self.Px
        if nom != "":
           Px0 = "Pn_"+nom
         
        Vdx = VectDih(1,self.Vd1x,self.Vd2x,ad,0) 
        Vb1 = VectRatio(Vdx,d+R)
        Vb1s = VectString2(Vb1)
        
        Vb2 = VectRatio(Vdx,R/2)
        Vb2s = VectString2(Vb2)
                      
        CodeAppend(self.CodeS,[
        "try:",
        "  Px="+Px0,
        "  R="+str(R),
        "  d="+str(d),
        "  Pna = geompy.MakeVertexWithRef(Px,"+Vb1s+")",
        "  Liste.append([Pna,\"Pna\"])",    
        "  P2a=geompy.MakeVertexWithRef(Pna,"+Vb2s+")",
        "  Liste.append([Pna,\"Pna\"])",  
        "  Vd2x0 = geompy.MakeVector(Pna,P2a)", 
        "  Liste.append([Vd2x0,\"Vd2x0\"])", 
        "  CercleExt = geompy.MakeCircle(Pna,Vd2x0,2*R)",
        "  S = geompy.MakeFaceWires([CercleExt], 1)",
        "  Liste.append([S ,\"S\"])",
        "  Bute = geompy.MakePipe( S ,Vd2x0)",
        "  Bute.SetColor(SALOMEDS.Color("+Couleur["Bute"]+"))",
        "  Bute_id=geompy.addToStudy(Bute,\"Bda_"+ self.Px +"\")",
        "  gg.createAndDisplayGO(Bute_id)",
        "  gg.setDisplayMode(Bute_id,1)",
        "  for x in Liste :",
        "    geompy.addToStudyInFather(Bute,x[0],x[1])",
         
        "except:",
        "  print ",
        "  print \"Butée:Erreur\"",
        "  for x in Liste :",
        "    geompy.addToStudy(x[0],x[1])",
        "  gg.createAndDisplayGO(O_id)",
        "  gg.setDisplayMode(O_id,1)",    
        ])  

    #---------------------------------------------------------------------------
    """
    Ajouter V:
    AFAIRE : Cas ou V=Vd1x dès le début
    """
    #---------------------------------------------------------------------------
    def Ajouter_Bi(self,A,Px,Bi):

        [Vdx,Secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx] = self.DicP[Px]
  
        if modelx in LesModeles_ROND:
            [R,e] =Secx
            Re = 1.15*R 
        elif modelx == "POUTRE_RECTANGLE":
            [Lmax,Lmin,e2,e1,angleP]=Secx 
            R=Lmax
            Re=Lmax   
         

        if Bi == "Bx":
            V1s="2*Re,0,0"
            V2s="R,0,0"
            V3s="-2*Re,0,0"
            V4s="-R,0,0"
            Vi =[0,x,x,x,x,x]
            
        elif Bi == "By":
            V1s="0,2*Re,0"
            V2s="0,R,0"
            V3s="0,-2*Re,0"
            V4s="0,-R,0"
            Vi =[x,0,x,x,x,x]
            
        elif Bi == "Bz":
            V1s="0,0,2*Re"
            V2s="0,0,R"
            V3s="0,0,-2*Re"
            V4s="0,0,-R"
            Vi =[x,x,0,x,x,x] 

        B = Bi + "_"+Px
        
        CodeAppend(self.CodeS,[
        "try:",
        "  Px="+Px,
        "  R="+str(R),
        "  Re="+str(Re),
        "  Liste=[]",
        "  Pna=geompy.MakeVertexWithRef(Px,"+V1s+")",
        "  Liste.append([Pna,\"Pna\"])",
        
        "  Pnb=geompy.MakeVertexWithRef(Px,"+V2s+")",
        "  Liste.append([Pnb,\"Pnb\"])",
        
        "  Vp=geompy.MakeVector(Pna,Pnb)",
        "  Liste.append([Vp,\"Vp\"])",
        
        "  Cone1 = geompy.MakeCone(Pna,Vp,Re,0,2*Re-R)",
        "  Liste.append([Cone1,\"Cone1\"])",
        
        "  P2a=geompy.MakeVertexWithRef(Px,"+V3s+")",
        "  Liste.append([P2a,\"P2a\"])",
        
        "  P2b=geompy.MakeVertexWithRef(Px,"+V4s+")",
        "  Liste.append([P2b,\"P2b\"])",  
        
        "  Vm=geompy.MakeVector(P2a,P2b)",
        "  Liste.append([Vm,\"Vm\"])",
        
        "  Cone2 = geompy.MakeCone(P2a,Vm,Re,0,2*Re-R)",
        "  Liste.append([Cone2,\"Cone2\"])",
        
        "  B=geompy.MakeCompound([Cone1,Cone2])",
        "  B.SetColor(SALOMEDS.Color("+Couleur["Bloc"]+"))",
        "  B_id=geompy.addToStudy(B,\""+ B +"\")",
        "  gg.createAndDisplayGO(B_id)",
        "  gg.setDisplayMode(B_id,1)",
        
        "  for x in Liste:",
        "    geompy.addToStudyInFather(B,x[0],x[1])",
        
        "except:",
        
        "  for x in Liste:",
        "    geompy.addToStudy(x[0],x[1])", 
     
        ])

        self.Ajouter_Liaison_Oblique(Px,Vi,"GLOBAL") 

     
       
           
    #---------------------------------------------------------------------------
    def Ajouter_Bride(self,A,nom,lien):
        
        [Vd,Secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx] = self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=Vd
        # RECUPERATION DES INFOS
        [Lb,masse]=ConvNFloat(A,2)
        [R,e]=self.Secx
        
        # INCREMENTATION
        self.nP += 1    
        
        # DEFINITION DES VARIABLES
        Pn = "Pn" + str(self.nP)+"_B"
        Pm = "Pm" + str(self.nP)
        Va = "Va" + str(self.nP)
        Vb = "Vb" + str(self.nP)
        Bride = "Bride"+str(self.nP)

        # PARTIE PRINCIPALE
       
        #Vecteur indiquant le centre de gravité à partir du centre
        Vd2 =VectRatio(self.Vd2x,Lb/2)
        Vd2s=VectString(Vd2)
        self.VPx =  AddVect([[1,self.VPx],[2,Vd2]]) 

        if lien != "" :  self.Ajouter_Liaison(lien)
        # Infos sur le point nommé
        if nom != "": Pn = nom
        self.DicP[Pn] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,Bride,modelx,"",self.SIF,self.Temp,self.Press] 
        
        CodeAppend(self.CodeS,[
        "try:",
        "  print \"Ajout de  "+ Bride + "\"", 
        "  Rb ="+str(1.5*R),
        "  eb ="+str(e+0.5*R),
        "  Lb = "+str(Lb),
        "  Liste=[]",
        "  "+Pm+"= geompy.MakeTranslationVectorDistance("+self.Px+",Vd2x,"+str(Lb/2)+")",
        "  Liste.append(["+Pm+",\""+Pm+"\"])",
        
        "  "+Pn+"= geompy.MakeTranslationVectorDistance("+Pm+",Vd2x,"+str(Lb/2)+")",
        "  Liste.append(["+Pn+",\""+Pn+"\"])",    
        
        "  "+Va+"= geompy.MakeVector("+self.Px+","+Pm+")",
        "  Liste.append(["+Va+",\""+Va+"\"])",
        
        "  "+Vb+" = geompy.MakeVector("+Pm+","+Pn+")", 
        "  Liste.append(["+Vb+",\""+Vb+"\"])",
        
        "  Vt = geompy.MakeVector("+self.Px+","+Pn+")", 
       
        "  "+Bride + "= geompy.MakeCompound([" + Va + "," + Vb + "])",
        "  Liste.append(["+Bride + ",\""+Bride+"\"])",     

        "  CercleExt = geompy.MakeCircle("+self.Px+",Vd2x,Rb)",
        "  Liste.append([CercleExt ,\"CercleExt\"])",
        
        "  CercleInt = geompy.MakeCircle("+self.Px+",Vd2x,Rb-eb)",
        "  Liste.append([CercleInt ,\"CercleInt\"])",
        
        "  S = geompy.MakeFaceWires([CercleExt, CercleInt], 1)",
        "  Liste.append([S ,\"S\"])",

        "  Bride3D = geompy.MakePipe( S ,Vt)",
        "  Bride3D.SetColor(SALOMEDS.Color("+Couleur["Bride"]+"))",
        "  Bride3D_id=geompy.addToStudy(Bride3D,\""+ Bride +"\")",
        "  gg.createAndDisplayGO(Bride3D_id)",
        "  gg.setDisplayMode(Bride3D_id,1)",
        

        "  for x in Liste :",
        "     geompy.addToStudyInFather(Bride3D,x[0],x[1])",

        "  "+Bride+"M = smesh.Mesh("+ Bride +")",
        "  Decoupage = "+Bride+"M.Segment()",
        "  Decoupage.NumberOfSegments("+str(1)+")",
        ]) 
        
        if self.iQUAD:
            CodeAppend(self.CodeS,[
            "  Quadratic_Mesh = Decoupage.QuadraticMesh()",
            ])
        
        CodeAppend(self.CodeS,[
        "  smesh.SetName("+Bride+"M,'"+Bride+"')",
        "  "+Bride+"M.Compute()",
        "  "+Bride+"M.GroupOnGeom("+self.Px+")",
        "  "+Bride+"M.GroupOnGeom("+Pn+")",
        "  "+Bride+"M.GroupOnGeom("+Pm+")",
        "  "+Bride+"M.GroupOnGeom("+Va+")",
        "  "+Bride+"M.GroupOnGeom("+Vb+")",
        
     
        "except:",
        "  print(\"Erreur Bride\")",
        "  for x in Liste:",
        "    geompy.addToStudy(x[0],x[1])",
        "  gg.createAndDisplayGO(O_id)",
        "  gg.setDisplayMode(O_id,1)", 
        ])
        
        self.LesMasses.append(Pm)
        exec("self.Les"+self.model+"s.extend([Va,Vb])")
        
        self.LesVs_iMat.append(Va)
        self.LesVs_iMat.append(Vb)
        if self.iTemp:self.LesVs_iTemp.extend([Va,Vb])
        
        self.LesRONDx4s_iSec.append(Va)
        self.LesRONDx4s_iSec.append(Vb)
        
      
        Lx =  TrouverLigne(self.CodeA,"#MASSE_DISCRET")
        CodeInsertI(self.CodeA,Lx,2,[
        "_F(",
        "   GROUP_MA='"+Pm+"A',",
        "   CARA='M_T_D_N',",
        "   VALE=("+str(masse/1000)+"),",
        "),",
        ])
        
        if self.model in ["TUYAU3M","TUYAU6M"]:
            self.Ajouter_GENE()
            if self.iPress : self.LesVs_iPress.extend([Va,Vb])



        self.LTout.append(Bride)
        self.Px = Pn
            

        
    #---------------------------------------------------------------------------
    def Ajouter_Bx(self,A,nom,lien):
        self.AddLesBi(A,nom,"Bx") 
     
    #---------------------------------------------------------------------------
    def Ajouter_By(self,A,nom,lien):
        self.AddLesBi(A,nom,"By") 
     
    #---------------------------------------------------------------------------
    def Ajouter_Bz(self,A,nom,lien):
        self.AddLesBi(A,nom,"Bz") 

    #---------------------------------------------------------------------------
    def Ajouter_CB(self,A,nom,lien):
        self.Supportx="CB"
        if nom=="":nom=self.Px
        self.LesSupports.append(["CB",A,nom,self.repere]) 
        self.Ajouter_Seisme()
        self.Supportx=""
       
    #---------------------------------------------------------------------------
    def Ajouter_GL(self,A,nom,lien):
        self.Supportx="GL"
        if nom=="":nom=self.Px
        self.LesSupports.append(["GL",A,nom,self.repere])  
        self.Ajouter_Seisme() 
        self.Supportx=""
          
    #---------------------------------------------------------------------------
    def Ajouter_Ca(self,A,nom,lien) :
           
        if self.model=="3D":
            self.Ajouter_Ca_3D(A,nom,lien)
        elif self.model in ["TUBE","TUYAU3M","TUYAU6M"]:
            self.Ajouter_Ca_1D(A,nom,lien)  
        else:
            AfficherErreur(["Model inconu pour Ca"])

    #---------------------------------------------------------------------------
    def Ajouter_Ca_3D(self,A,nom,lien) :

        [Vdx,Secx,self.VPx,Vx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=self.DicP[self.Px][0]

        # RECUPERATION DES INFOS
        [rc,ac,ad]=VectNum(A)   
        [R,e]=self.Secx   
        
        # INCREMENTATION
        self.nP += 1
        
        # VARIABLES
        acr =ac * math.pi / 180
        adr = ad * math.pi / 180

        Pn = "Pn_"+str(self.nP)
        if nom != "": Pn = nom   

        Pm = "Pm_"+str(self.nP)
        Pc = "Pc_"+str(self.nP)
        

        # PARTIE PRINCIPALE  
        self.Vd2x = VectRatio(self.Vd2x,rc)
        Vd2xs = VectString2(self.Vd2x)
        
        VPc = VectDih(rc,self.Vd1x,self.Vd2x,ad,0)
        VPcs = VectString2(VPc)
        VPco = VectOpp(VPc)
        
        Vaxe = ProdVect(VPco,self.Vd2x)
        Vaxe = VectRatio(Vaxe,rc)
        Vas = VectString2(Vaxe)    
        
        VP1 = RotVect(VPco,Vaxe,ac)
        VP1s = VectString2(VP1)
        
        VPm = RotVect(VPco,Vaxe,ac/2)
        VPms = VectString2(VPm)   
         
        Vd3x = VectDih(rc,self.Vd1x,self.Vd2x,ad,ac-90)
        Vd3xs = VectString2(Vd3x)
        
        
        # Calcul des coefficients
        h=(e*R)/pow((R-e/2),2)
        #Coefficient de fléxibilté
        Cflex=1.65/h
        # Coef. d'intensification de contrainte
        SIF=0.9/(h**0.666666)
        
        #Calcul de la position du nouveau point
        
        self.VPx=AddVect([[1,self.VPx],[1,VPc],[1,VP1]])
        
        Ca3D = "Ca3D"+str(self.nP)

        # Infos sur le point nommé
        self.Ajouter_Liaison(lien)
        SIF=max(2.0,self.SIF)
        self.DicP[Pn] =  [[VectNorm(self.Vd2x),VectNorm(Vd3x)],self.Secx,self.VPx,Ca3D,"3D", Ca3D+"Sx2",SIF,self.Temp,self.Press] 

        CodeAppend(self.CodeS,[
        "try:",
        "  print(\"Ajout du coude 3D"+  Ca3D+"\")",
        "  Liste=[]",
        "  R="+str(R),
        "  e="+str(e),
        "  rc = "+ str(rc),
        "  Px = "+self.Px,
        
        "  P2 = geompy.MakeVertexWithRef(Px,"+Vd2xs+")",
        "  Vd2x=geompy.MakeVector(Px,P2)",
        "  Liste.append([Vd2x,\"Vd2x\"])",

        "  Pc = geompy.MakeVertexWithRef(Px,"+VPcs+")",
        "  Liste.append([Pc,\"Pc\"])",
        
        "  VPc = geompy.MakeVector(Px,Pc)", 
        "  Liste.append([VPc,\"VPc\"])",
        
        "  Pa = geompy.MakeVertexWithRef(Pc,"+Vas+")",   
        "  Liste.append([Pa,\"Pa\"])",
        
        "  Vaxe = geompy.MakeVector(Pc,Pa)",
        "  Liste.append([Vaxe,\"Vaxe\"])",
        
        "  Pn = geompy.MakeRotation(Px,Vaxe,"+str(acr)+")",
        "  "+Pn+"=Pn",
        "  Liste.append([Pn,\""+Pn+"\"])",

        "  P3 = geompy.MakeVertexWithRef(Pn,"+Vd3xs+")", 
        "  Vd3x=geompy.MakeVector(Pn,P3)",
        "  Liste.append([Vd3x,\"Vd3x\"])",

        "  V= geompy.MakeArcCenter(Pc,Px," +Pn+")",
        "  Liste.append([V,\"V\"])",

        "  CercleExt = geompy.MakeCircle(Px,Vd2x,R)",
        "  Liste.append([CercleExt,\"CercleExt\"])",

        "  [Po] = geompy.SubShapeAllSorted(CercleExt,geompy.ShapeType[\"VERTEX\"])  ",  
        "  Liste.append([Po,\"Po\"])",
        
        "  CercleInt = geompy.MakeCircle(Px,Vd2x,R-e)",
        "  Liste.append([CercleInt,\"CercleInt\"])",
        
        "  S = geompy.MakeFaceWires([CercleExt, CercleInt], 1)",
        "  Liste.append([S,\"S\"])",

    #Rotation de S pour la partitionnement de Ca3D

        "  V1 = geompy.MakeVector(Px,Po)",
        "  anglerot=geompy.GetAngleRadians(V1,Vd3x)",

        "  S2 = geompy.MakeRotation(S, Vd2x, anglerot)",
        "  Liste.append([S2,\"S2\"]) ",
        
        "  "+Ca3D+" =  geompy.MakePipe( S2 , V )",
    #    "  Liste.append(["+Ca3D+",\""+Ca3D+"\"])",    
        
        "  Plan = geompy.MakePlane(Px,Vaxe,R*10)",
        "  Liste.append([Plan,\"Plan\"]) ", 
         
        "  "+Ca3D+" = geompy.MakeHalfPartition("+Ca3D+",Plan)",
        "  "+Ca3D+"_id=geompy.addToStudy("+Ca3D+",\""+ Ca3D +"\")",
        "  gg.createAndDisplayGO("+Ca3D+"_id)",
        "  gg.setDisplayMode("+Ca3D+"_id,1)",   
        
        "  p = geompy.MakeTranslationVectorDistance(Px,VPc, R-e/2)",
        "  Liste.append([p,\"p\"])",  
          
        "  E = geompy.GetShapesNearPoint("+Ca3D+",p ,geompy.ShapeType[\"EDGE\"],e/8)",
        "  Liste.append([E,\"E\"])",  
        
        "  E2 = geompy.GetShapesNearPoint("+Ca3D+",Po ,geompy.ShapeType[\"EDGE\"],e/8)",
        "  Liste.append([E2,\"E2\"])", 
        
    #Bug : Pour trouver les surfaces , la fonction geompy.GetFaceByNormale ne fonctionne pas.
        
        "  LSx = geompy.GetShapesOnPlane("+Ca3D+",geompy.ShapeType[\"FACE\"],Vd2x,GEOM.ST_ON)",
        "  "+Ca3D+"Sx = geompy.MakeCompound(LSx)",
        "  Liste.append(["+Ca3D+"Sx,\""+Ca3D+"Sx\"])", 
        
        "  LSx = geompy.GetShapesOnPlane("+Ca3D+",geompy.ShapeType[\"FACE\"],Vd3x,GEOM.ST_ON)",
        "  "+Ca3D+"Sx2 = geompy.MakeCompound(LSx)",
        "  Liste.append(["+Ca3D+"Sx2,\""+Ca3D+"Sx2\"])",
        
        "  for x in Liste :",
        "       geompy.addToStudyInFather("+Ca3D+",x[0],x[1])",
        
        "except:",
        "  print(\"    =>ERREUR\")",
        "  for x in Liste :",
        "       geompy.addToStudy(x[0],x[1])",
        "  gg.createAndDisplayGO(O_id)",
        "  gg.setDisplayMode(O_id,1)",
        
        #  Maillage
        "try:",
        "  #  Maillage",
        "  print(\"     Maillage\")",
        "  "+Ca3D+"M = smesh.Mesh("+Ca3D+")", 
        "  "+Ca3D+"M.Quadrangle()",
        "  Hexa_3D_3 = smesh.CreateHypothesis('Hexa_3D')",
        "  "+Ca3D+"M.AddHypothesis(Hexa_3D_3)",
      
        "  Regular_1D_1 = "+Ca3D+"M.Segment()  ",
        "  n = int(math.pi*R/(2*e))",
        "  Nb_Segments_1 = Regular_1D_1.NumberOfSegments(n)",
        "  Nb_Segments_1.SetDistrType( 0 )",
        
        "  Regular_1D_2 = "+Ca3D+"M.Segment(geom=E)",
        "  Nb_Segments_2 = Regular_1D_2.NumberOfSegments(1)",
        "  Nb_Segments_2.SetDistrType( 0 )",
        "  Regular_1D_2.Propagation()",    
        
        "  Regular_1D_3 = "+Ca3D+"M.Segment(geom=E2)",
        "  Nb_Segments_3 = Regular_1D_3.NumberOfSegments(n)",
        "  Nb_Segments_3.SetDistrType( 0 )",
        "  Regular_1D_3.Propagation()",

        "  "+Ca3D+"M.Compute()",

        "  smesh.SetName( "+Ca3D+"M , \""+Ca3D+"\")",  
        "  "+Ca3D+"M.GroupOnGeom("+Ca3D+")",
        "  "+Ca3D+"M.GroupOnGeom("+Ca3D+"Sx)",
        "  "+Ca3D+"M.GroupOnGeom("+Ca3D+"Sx2)",
        
        "except:",
        "  print(\"    =>ERREUR\")",
        ])
        self.Les3Ds.extend([Ca3D,Ca3D+"Sx",Ca3D+"Sx2"])
        self.LesVs_iMat.extend([Ca3D,Ca3D+"Sx",Ca3D+"Sx2"])
        
        if modelx in "TUBE":

            # Définition des liaisons 3D-TUBE",
            Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_POUTRE")
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   OPTION='3D_POU',",
            "   GROUP_MA_1 ='"+Ca3D+"Sx',",
            "   GROUP_NO_2 ='"+self.Px+"',",
            "),",
            ])   
            
        elif modelx in ["TUYAU3M","TUYAU6M"]:

            # Définition des liaisons 3D-TUBE",
            Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_TUYAU")
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   OPTION='3D_TUYAU',",
            "   GROUP_MA_1 ='"+Ca3D+"Sx',",
            "   GROUP_NO_2 ='"+self.Px+"',",
            "),",
            ])
                
        elif modelx=="3D":
            
            Lx = TrouverLigne(self.CodeA,"#LIAISON_MAIL")
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   TYPE_RACCORD='MASSIF',",
            "   GROUP_MA_ESCL='"+Vx+"Sx2',",
            "   GROUP_MA_MAIT='"+Ca3D+"Sx',",
            "),",
            ])

        self.Vd1x = VectNorm(self.Vd2x)
        self.Vd2x = VectNorm(Vd3x)

        self.LTout.append(Ca3D)  
        self.Px = Pn


    #---------------------------------------------------------------------------
    def Ajouter_Ca_1D(self,A,nom,lien) :
  
        # RECUPERATION DES INFOS
        [Vdx,Secx,self.VPx,Vx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=self.DicP[self.Px][0]
        [rc,ac,ad]=VectNum(A)   
        [R,e]=self.Secx   
        # INCREMENTATION
        self.nP += 1 
        
        # VARIABLES
        acr = ac * math.pi / 180
        adr = ad * math.pi / 180
        
        Pn = "Pn_"+str(self.nP)
        if nom!= "": Pn = nom
        self.Pn=Pn
        Pm = "Pm_"+str(self.nP)
        V = "COU"+str(self.nP)
        self.V=V
        Pc = "Pc_"+str(self.nP)
        

        # PARTIE PRINCIPALE  
        Vd2rc = VectRatio(self.Vd2x,rc)
        Vd2rcs = VectString2(Vd2rc)
        
        VPc = VectDih(rc,self.Vd1x,self.Vd2x,ad,0)
        VPcs = VectString2(VPc)
        
        VPcg=AddPVect(self.VPx,VPc)
        VPcgs = VectString2(VPcg)
        
        VPco = VectOpp(VPc)
        
        Vaxe = ProdVect(VPco,self.Vd2x)
        Vaxe = VectRatio(Vaxe,rc)
        Vas = VectString2(Vaxe)    
        
        VPn = RotVect(VPco,Vaxe,ac)
        VPns = VectString2(VPn)
       
        Vd3x = VectDih(1,self.Vd1x,self.Vd2x,ad,ac-90)
        Vd3xs = VectString2(Vd3x)

        # Calcul des coefficients
        h=(e*rc)/pow((R-e/2),2)
        #Coefficient de fléxibilté
        Cflex=1.65/h
        # Coef. d'intensification de contrainte
        SIF=0.9/(h**0.666666)
        
        #Calcul de la position du nouveau point
        self.VPx= AddVect([[1,self.VPx],[1,VPc],[1,VPn]])
        
        # Infos sur l'élément précédent

        CodeAppend(self.CodeS,[
        "try:",
        "  print(\"Ajout de "+ V + "\")",
        "  Liste=[]",
        "  rc = "+ str(rc),
        "  acr = "+ str(acr),
        "  adr = "+ str(adr),
        
        "  Pcg = geompy.MakeVertex("+VPcgs+")",
        "  Liste.append([Pcg,\"Pcg\"])",
        
        "  Pc = geompy.MakeVertexWithRef("+self.Px+","+VPcs+")",
        "  Liste.append([Pc,\"Pc\"])",
        
        "  Pa = geompy.MakeVertexWithRef(Pc,"+Vas+")",   
        "  Liste.append([Pa,\"Pa\"])",
        
        "  Vaxe = geompy.MakeVector(Pc,Pa)",
        "  Liste.append([Vaxe,\"Vaxe\"])",
        
        "  "+Pn+" = geompy.MakeRotation("+self.Px+",Vaxe,acr)",
    #    "  Liste.append(["+Pn+",\""+Pn+"\"])",

        "  "+V+" = geompy.MakeArcCenter(Pc,"+self.Px+","+Pn+")",
        "  Liste.append(["+V+",\""+V+"\"])",

    #Bug: Contrairement à ce qui est fait avec Vc, pour Ca il faut passer par 
    #     la création de points à l'aide de geompy.GetSame!    
        "  "+Pn+" = geompy.GetSame("+V+","+Pn+")",
        "  Liste.append(["+Pn+",\""+Pn+"\"])",
        
        "  "+self.Px+" = geompy.GetSame("+V+","+self.Px+")",
        "  Liste.append(["+self.Px+",\""+self.Px+"\"])",
        
        "  CercleExt = geompy.MakeCircle("+self.Px+",Vd2x,R)",
        "  Liste.append([CercleExt ,\"CercleExt\"])",
        "  if R>e:",
        "      CercleInt = geompy.MakeCircle("+self.Px+",Vd2x,R-e)",
        "      Liste.append([CercleInt ,\"CercleInt\"])",
        
        "      S = geompy.MakeFaceWires([CercleExt, CercleInt], 1)",
        "      Liste.append([S ,\"S\"])",

        "  else:",
        "      S = geompy.MakeFaceWires([CercleExt], 1)",
        "      Liste.append([S ,\"S\"])",

        "  Pipe = geompy.MakePipe( S ,"+V+")",
        "  Pipe.SetColor(SALOMEDS.Color("+Couleur[self.model]+"))",
        "  Pipe_id=geompy.addToStudy(Pipe,\""+ V +"_3D\")",
        "  gg.createAndDisplayGO(Pipe_id)",
        "  gg.setDisplayMode(Pipe_id,1)",
        "  Px="+Pn,
        "  Vd2x = geompy.MakeVectorDXDYDZ("+Vd3xs+")", 
        
        "  for x in Liste :",
        "     geompy.addToStudyInFather(Pipe,x[0],x[1])",
        
        "except:",
        "  ERREUR=True",
        "  print (\"   =>ERREUR géométrie!\")",
        "  for x in Liste :",
        "     geompy.addToStudy(x[0],x[1])",
        
        ])

        CodeAppend(self.CodeS,[
        "try:",
        "  "+V+"M = smesh.Mesh("+ V +")",
        "  Decoupage = "+V+"M.Segment()",
        "  Decoupage.NumberOfSegments("+str(8)+")",
    #    "  Type = Decoupage.LocalLength(R/2)",
    #    "  Type.SetPrecision(R/10),",
        ]) 
        
        if self.iQUAD or self.model in ["TUYAU3M","TUYAU6M"]:
            CodeAppend(self.CodeS,[
            "  Quadratic_Mesh = Decoupage.QuadraticMesh()",
            ])
        
        CodeAppend(self.CodeS,[ 
        "  smesh.SetName("+V+"M,'"+V+"')",
        "  "+V+"M.Compute()",
        "  "+V+"M.GroupOnGeom("+self.Px+")",
        "  "+V+"M.GroupOnGeom("+Pn+")",
        "  "+V+"M.GroupOnGeom("+V+")",
        
        "except:",
        "  ERREUR=True",
        "  print (\"   =>ERREUR maillage!\")",
        ])
        
        xCf=TrouverLigne(self.CodeA,"#CENTRE_COURBURE")
        CodeInsertI(self.CodeA,xCf,2,[
        "_F(",
        "   GROUP_MA='"+ V + "',",
        "   CENTRE=("+VPcgs+"),",
        "   COEF_FLEX="+str(Cflex)+",",
        "   INDI_SIGM="+str(SIF)+",",
        "   PRECISION=0.001,",
        "),"
        ])
     
        modelx=self.DicP[self.Px][4] 
        V3DSx=self.DicP[self.Px][5] 

        if modelx=="3D":
            
            # Définition des liaisons 3D-TUBE",
            xL3D=TrouverLigne(self.CodeA,"#LIAISON_3D_POUTRE")
            CodeInsertI(self.CodeA,xL3D,2,[
            "_F(",
            "   OPTION='3D_POU',",
            "   GROUP_MA_1 ='"+V3DSx+"',",
            "   GROUP_NO_2 ='"+self.Px+"',",
            "),",
            ])  
  
        self.LesRONDs_iSec.append(V)
        self.LesVs_iMat.append(V)
        if self.iTemp : self.LesVs_iTemp.append(V)
        if self.iPress : self.LesVs_iPress.append(V)
        self.LTout.append(V)
        if self.model in ["TUYAU3M","TUYAU6M"]:
            self.Ajouter_GENE()
            if self.iPress : self.LesVs_iPress.append(V)
        exec("self.Les"+self.model+"s.append(V)")
        self.Vd1x=self.Vd2x
        self.Vd2x=Vd3x
        if SIF > SIFx:self.DicP[self.Px][6]=SIF    
        self.Px=Pn
        self.Ajouter_Liaison(lien)    
        SIFn=SIF  
        if self.SIF > SIF : SIFn = self.SIF
        self.DicP[Pn] =[[self.Vd1x,self.Vd2x],self.Secx,self.VPx,V,self.model,"",SIFn,self.Temp,self.Press]  
        self.SIF=1
        
    #---------------------------------------------------------------------------
    def Ajouter_DDL(self,Cd) :
        
        if Cd in ["Bx","By","Bz","BRx","BRy","BRz"]:
            self.nDDL+=1
        elif Cd in ["CG","GL"]:
            self.nDDL+=2
        elif Cd in ["CB"]:
            self.nDDL+=3
        elif Cd in ["PF"]:
            self.nDDL+=6
        else:
            AfficherErreur([ "Erreur: Blocage inconnu"])


    #--------------------------------------------------------------------------- 
    def Ajouter_Fleche(self,Pn,An,c,Rf):

        Fleche="Fleche_"+Pn
        As=VectString2(An)
        Cs=VectString2(c)
        CodeAppend(self.CodeS,[
        "try:",
        "  Liste=[]",
        "  Pf="+Pn,
        "  Liste.append([Pf,\"Pf\"])",
        
        "  Rf="+str(Rf),
        "  P2=geompy.MakeVertexWithRef(Pf,"+As+")",
        "  Liste.append([P2,\"P2\"])",
        
        "  V=geompy.MakeVector(Pf,P2)",
        "  Liste.append([V,\"V\"])",
        
        "  S=geompy.MakeCircle(Pf,V,Rf)",
        "  Liste.append([S,\"S\"])",
        
        "  Tige = geompy.MakePipe( S , V )",
        "  Liste.append([Tige,\"Tige\"])",  
        
        "  Pointe = geompy.MakeCone(P2 ,V,2*Rf,0,5*Rf)",
        "  Liste.append([Pointe,\"Pointee\"])",    
        
        "  Fleche = geompy.MakeCompound([Tige,Pointe])",
        "  "+Fleche+" =Fleche",
        "  Fleche.SetColor(SALOMEDS.Color("+Cs+"))",
        "  Fleche_id=geompy.addToStudy(Fleche ,\""+ Fleche +"\")",
        "  gg.createAndDisplayGO(Fleche_id)",
        "  gg.setDisplayMode(Fleche_id,1)",
        "  for x in Liste:",
        "    geompy.addToStudyInFather(Fleche,x[0],x[1])",
        "except:",
        "  print\"Erreur fleche effort!\"",
        "  for x in Liste:",
        "    geompy.addToStudy(x[0],x[1])",    
        "  gg.createAndDisplayGO(O_id)",
        "  gg.setDisplayMode(O_id,1)",
        ])

    #---------------------------------------------------------------------------
    def Ajouter_Fn(self,A,nom,lien):
        [Fx,Fy,Fz,N]=ConvNFloat(A,4)  
        F=[Fx,Fy,Fz]
        if nom!="":
           if not(nom in self.DicP):
              AfficherErreur(["Affectation d'une force en un point inconu!"])
        
        else: nom = self.Px
        
        self.LesForces.append([nom,F])
        
        tex=""
        for i,x in enumerate(F):
                tex += FORCE[i]+"="+str(x)+", "
  
        
        Lx  =  TrouverLigne(self.CodeA,"#FORCE_NODALE")
        CodeInsertI(self.CodeA,Lx,1,[
        "_F(",
        "GROUP_NO='" + nom + "',",
        tex,
        "),"
        ])
        

        if N!=0:
            Lx=TrouverLigne(self.CodeA,"#RAMPE")
            if Lx==0 :
                AfficherErreur(["L'utilisation d'une rampe se fait avec STATIQUE_NON_LINEAIRE"])
            else:
                Lx2=TrouverLigne(self.CodeA,"#YA_RAMPE")
                if Lx2==0:
                    CodeInsert(self.CodeA,Lx,[
                    "#YA_RAMPE",
                    "RAMPE=DEFI_FONCTION(",
                    "       NOM_PARA='INST',",
                    "       VALE=(0.0,0.0,1,1),",
                    "       PROL_DROITE='EXCLU',",
                    "       PROL_GAUCHE='EXCLU',",
                    ");",
                    ])
                
            Lx=TrouverLigne(self.CodeA,"#STN:RAMPE")
            if Lx==0 :
                AfficherErreur(["L'utilisation d'une rampe se fait avec STATIQUE_NON_LINEAIRE"])
            else:
                CodeInsertI(self.CodeA,Lx,3,[
                "FONC_MULT=RAMPE",
                ])
                
            Lx=TrouverLigne(self.CodeA,"#STN_NOMBRE")
            self.CodeA.pop(Lx-1)
            CodeInsertI(self.CodeA,Lx,1,[
            "NOMBRE="+str(N)+",",
            ])
        


      
    #---------------------------------------------------------------------------
    def Ajouter_Fnx(self,A,nom,lien):
        [F,N]=ConvNFloat(A,2)
        self.Ajouter_Fn([F,0,0,N],nom,lien)
        
    #---------------------------------------------------------------------------
    def Ajouter_Fny(self,A,nom,lien):
        [F,N]=ConvNFloat(A,2)
        self.Ajouter_Fn([0,F,0,N],nom,lien)
        
    #---------------------------------------------------------------------------
    def Ajouter_Fnz(self,A,nom,lien):
        [F,N]=ConvNFloat(A,2)
        self.Ajouter_Fn([0,0,F,N],nom,lien)
        
        

    #---------------------------------------------------------------------------
    def Ajouter_FnO(self,A,nom,lien,Dir):
        if not(self.iCalc_Dynamique): 
            self.Ajouter_Fn(A[:3],nom,lien)
        else:
            [Fx,Fy,Fz,omega,phase]=ConvNFloat(A,5)  
            F=[Fx,Fy,Fz]
            if nom!="":
               if not(nom in self.DicP):
                  AfficherErreur(["Affectation d'une force en un point inconu!"])
            
            else: nom = self.Px
            
            self.LesForces.append([nom,F])
            
            tex=""
            for i,x in enumerate(F):
                    tex += FORCE[i]+"="+str(x)+", "
      
            nomi=nom+Dir
            
            Lx  =  TrouverLigne(self.CodeA,"#DEF_FONCTION")
            CodeInsert(self.CodeA,Lx,[
            "FOA"+nomi+"=AFFE_CHAR_MECA(",
            "       MODELE=MODMECA,",
            "       FORCE_NODALE=(",
            "           _F(",
            "               GROUP_NO='" + nom + "',",
            "               "+tex,
            "           ),",
            "       ),",
            ");",
            "",
            "FOE"+nomi+"=CALC_VECT_ELEM(",
            "       OPTION='CHAR_MECA',",
            "       CHARGE=FOA"+nomi+",",
            ");",
            "",
            "FOV"+nomi+"=ASSE_VECTEUR(",
            "       VECT_ELEM=FOE"+nomi+",",
            "       NUME_DDL=NUMEDDL,",
            ");",
            "FF"+nomi+" = FORMULE(",
            "       VALE='sin(6.28*"+str(omega)+" *INST+"+str(phase)+")',",
            "       NOM_PARA='INST',",
            ");",
            ])
            
            Lx  =  TrouverLigne(self.CodeA,"#DEF_FONC_MULT")
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(    VECT_ASSE=FOV"+nomi+",",
            "       FONC_MULT=FF"+nomi+",",
            "),",
            ])

      
        
        
        
    #---------------------------------------------------------------------------
    def Ajouter_FnxO(self,A,nom,lien):
        self.Ajouter_FnO([A[0],0,0,A[1]],nom,lien,"X")
        
    #---------------------------------------------------------------------------
    def Ajouter_FnyO(self,A,nom,lien):
        self.Ajouter_FnO([0,A[0],0,A[1]],nom,lien,"Y")
        
    #---------------------------------------------------------------------------
    def Ajouter_FnzO(self,A,nom,lien):
        self.Ajouter_FnO([0,0,A[0],A[1]],nom,lien,"Z")
   
    #---------------------------------------------------------------------------
    def Ajouter_FreqMax(self,A,nom,lien):
        self.freqMax=ConvNInt(A,1)
    
    #---------------------------------------------------------------------------
    def Ajouter_GENE(self):   
    
        if self.model in ["TUYAU3M","TUYAU6M"]:
            vd3x=VectNorm(ProdVect(self.Vd2x,self.Vd1x))
            vd3s=VectString2(vd3x)
            if self.iDebutTUYAU:
                Lx=TrouverLigne(self.CodeA,"#ORIENTATION")
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   GROUP_NO='"+self.Px+"',",
                "   CARA='GENE_TUYAU',",
                "   VALE=("+vd3s+"),",
                "),",
                ])
                self.iDebutTUYAU=False

    #---------------------------------------------------------------------------   
    def Ajouter_Liaison(self,lien):
        
        if lien=="":
            pass
        elif lien == "s":
            self.SIF=1.5
            self.Ajouter_Soudure()
            
        else:
            AfficherErreur(["Liaison non modélisée pour le moment"])
            


    #---------------------------------------------------------------------------   
    def Ajouter_LgElement(self,A,nom,lien):
        
        [self.LgElement]=ConvNFloat(A,1)



    #---------------------------------------------------------------------------  
    def Ajouter_Lis(self,A,nom,lien):
        
        # Création du point suivant
        V = "Lis"+str(self.nP)

    #    Ajouter_Liaison(Liaison,[P0,model0],[Pn,model])
        
        CodeAppend(self.CodeS,[
        "try:",
        "  print(\"Ajouter_Vd_"+self.model+ ": "+ V + "\")",
        "  Liste=[]",
        "  V = geompy.MakeVector("+self.Px+","+nom+")",
        "  Liste.append([V,\""+ V +"\"])",
        "  "+V+"=V",
        "  CercleExt = geompy.MakeCircle("+self.Px+",V,R/2)",
        "  Liste.append([CercleExt ,\"CercleExt\"])",
        "  S = geompy.MakeFaceWires([CercleExt], 1)",
        "  Liste.append([S ,\"S\"])",
        "  Pipe = geompy.MakePipe(S ,V)",
        "  Pipe.SetColor(SALOMEDS.Color("+Couleur["Rigide"]+"))",
        "  Pipe_id=geompy.addToStudy(Pipe,\""+ V +"\")",
        "  gg.createAndDisplayGO(Pipe_id)",   
        "  gg.setDisplayMode(Pipe_id,1)",

        "  for x in Liste :",
        "     geompy.addToStudyInFather(Pipe,x[0],x[1])",
        "except:",
        "  ERREUR=True",
        "  print (\"   =>ERREUR!\")",
        "  for x in Liste :",
        "     geompy.addToStudy(x[0],x[1])",
        "  gg.setDisplayMode(O_id,0)",

        "try:",
        "  #   Maillage  ",
        "  PipeM = smesh.Mesh("+ V +")",
        "  Decoupage = PipeM.Segment()",
        "  Decoupage.NumberOfSegments("+str(1)+")",
        "  smesh.SetName(PipeM,'"+V+"')",
        "  PipeM.Compute()",
        "  "+V+"M=PipeM",
        "  PipeM.GroupOnGeom("+V+")",
        "except:",
        "  ERREUR=True",
        "  print (\"   =>ERREUR!\")",
        ])


        xAM =  TrouverLigne(self.CodeA,"#LIAISON_SOLIDE")
        CodeInsertI(self.CodeA,xAM,2,[
        "_F(",
        "GROUP_MA=('"+V+"'),",
        "),",
        ])
        
        self.LTout.append(V)
        
        self.Ajouter_Liaison(lien)
        

    #---------------------------------------------------------------------------
    def Ajouter_Maillage(self,A,nom,lien):
        if nom=="QUAD" :
            self.iQUAD=True
        else:
            self.iQUAD=False

    #---------------------------------------------------------------------------
    def Ajouter_Masse(self,A,nom,lien):
        m=float(A[0])  
        if nom=="": nom=self.Px
       
        R=max(self.Secx)
        
        Ms="Masse"+str(self.nP)

        CodeAppend(self.CodeS,[
        "R="+str(R),
        "print(\"Ajout d'une masse\")", 
        "Cercle = geompy.MakeCircle("+self.Px+",Vd2x,R*1.1)",
        "Surface = geompy.MakeFaceWires([Cercle], 1)",
        Ms+" = geompy.MakePrismVecH2Ways(Surface, Vd2x,R/2)",
        Ms+".SetColor(SALOMEDS.Color("+Couleur["Masse"]+"))",
        "P_id = geompy.addToStudy("+Ms+",\""+Ms+"\")",
        "gg.createAndDisplayGO(P_id)",
        "gg.setDisplayMode(P_id,1)",
        ])
        

        self.LesMasses.append(self.Px)
        
        Lx =  TrouverLigne(self.CodeA,"#MASSE_DISCRET")
        CodeInsertI(self.CodeA,Lx,2,[
        "_F(",
        "   GROUP_MA='"+self.Px+"A',",
        "   CARA='M_T_D_N',",
        "   VALE=("+str(m/1000)+"),",
        "),",
        ])
        

    #---------------------------------------------------------------------------
    def Ajouter_Mat(self,A,nom,lien):
        
        self.Inserer_LesVs_iMat()
        self.matx=nom



    #---------------------------------------------------------------------------
    def Ajouter_Mn(self,A,nom,lien):
             
        [Mx,My,Mz,N]=ConvNFloat(A,4)  
        M=[Mx,My,Mz]
        if nom!="":
           if not(nom in self.DicP):
              AfficherErreur(["Affectation d'une force en un point inconu!"])
        
        else: nom = self.Px
        
        self.LesMoments.append([nom,M])
        
        tex=""
        for i,x in enumerate(M):
                tex += MOMENT[i]+"="+str(x)+", "
  
        
        Lx  =  TrouverLigne(self.CodeA,"#FORCE_NODALE")
        CodeInsertI(self.CodeA,Lx,1,[
        "_F(",
        "GROUP_NO='" + nom + "',",
        tex,
        "),"
        ])
        

        if N!=0:
            Lx=TrouverLigne(self.CodeA,"#STN:RAMPE")
            if Lx==0 :
                AfficherErreur(["L'utilisation d'une rampe se fait avec STATIQUE_NON_LINEAIRE"])
            else:
                CodeInsertI(self.CodeA,Lx,3,[
                "FONC_MULT=RAMPE",
                ])
                
            Lx=TrouverLigne(self.CodeA,"#STN_NOMBRE")
            CodeInsertI(self.CodeA,Lx,2,[
            "NOMBRE="+str(N)+",",
            ])
            


    #---------------------------------------------------------------------------
    def Ajouter_Mnx(self,A,nom,lien):
        self.Ajouter_Mn([A[0],0,0],nom,lien)
        
    #---------------------------------------------------------------------------
    def Ajouter_Mny(self,A,nom,lien):
        self.Ajouter_Mn([0,A[0],0],nom,lien)
        
    #---------------------------------------------------------------------------
    def Ajouter_Mnz(self,A,nom,lien):
        self.Ajouter_Mn([0,0,A[0]],nom,lien)
        
   #---------------------------------------------------------------------------
    def Ajouter_MnO(self,A,nom,lien):
        if not(self.iCalc_Dynamique): 
            self.Ajouter_Mn(A[:3],nom,lien)
        else:
            [Mx,My,Mz,omega,phase]=ConvNFloat(A,5)  
            M=[Mx,My,Mz]
            if nom!="":
               if not(nom in self.DicP):
                  AfficherErreur(["Affectation d'un moment en un point inconu!"])
            
            else: nom = self.Px
            
            self.LesMoments.append([nom,M])
            
            tex=""
            for i,x in enumerate(M):
                    tex += MOMENT[i]+"="+str(x)+", "
      
            
            Lx  =  TrouverLigne(self.CodeA,"#DEF_FONCTION")
            CodeInsert(self.CodeA,Lx,[
            "MOA"+nom+"=AFFE_CHAR_MECA(",
            "       MODELE=MODMECA,",
            "       FORCE_NODALE=(",
            "           _F(",
            "               GROUP_NO='" + nom + "',",
            "               "+tex,
            "           ),",
            "       ),",
            ");",
            "",
            "MOE"+nom+"=CALC_VECT_ELEM(",
            "       OPTION='CHAR_MECA',",
            "       CHARGE=MOA"+nom+",",
            ");",
            "",
            "MOV"+nom+"=ASSE_VECTEUR(",
            "       VECT_ELEM=MOE"+nom+",",
            "       NUME_DDL=NUMEDDL,",
            ");",
            "MF"+nom+" = FORMULE(",
            "       VALE='sin(6.28*"+str(omega)+" *INST+"+str(phase)+")',",
            "       NOM_PARA='INST',",
            ");",
            ])
            
            Lx  =  TrouverLigne(self.CodeA,"#DEF_FONC_MULT")
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(    VECT_ASSE=MOV"+nom+","
            "       FONC_MULT=MF"+nom+",",
            "),",
            ])

      
        
              
        
    #---------------------------------------------------------------------------
    def Ajouter_MnxO(self,A,nom,lien):
        self.Ajouter_MnO([A[0],0,0],nom,lien)
        
    #---------------------------------------------------------------------------
    def Ajouter_MnyO(self,A,nom,lien):
        self.Ajouter_MnO([0,A[0],0],nom,lien)
        
    #---------------------------------------------------------------------------
    def Ajouter_MnzO(self,A,nom,lien):
        self.Ajouter_MnO([0,0,A[0]],nom,lien)  
        
        
        
    #---------------------------------------------------------------------------
    def Ajouter_Model(self,A,nom,lien):
        self.Inserer_LesRONDs_iSec()
        self.model = nom
        #self.iDebutTUYAU=True
        if nom in ["TUYAU3M","TUYAY6M"]: 
            self.iQUAD=True
        else:
            self.iQUAD=False
            
            
    #---------------------------------------------------------------------------
    def Ajouter_NbElement(self,A,nom,lien):    
        [self.NbElement]=ConvNInt(A,1)        
        
    #---------------------------------------------------------------------------
    def Ajouter_P(self,A,nom,lien) :
        self.iDebutTUYAU=True
        self.nP += 1
        self.Px = "Pn_"+str(self.nP)
        if nom!="": self.Px=nom
        self.VPx =  VectNum(A)
        VPxs =  VectString2(self.VPx)        

        self.DicP[self.Px] = [[self.Vd1x0,self.Vd2x0],self.Secx,self.VPx,"",self.model,"",1,self.Temp,self.Press]   
        self.Vd1x=self.Vd1x0
        self.Vd2x=self.Vd2x0
        Vd2xs = VectString2(self.Vd2x0)
        CodeAppend(self.CodeS,[
        "#",
        self.Px+"= geompy.MakeVertex("+VPxs+")",
        "geompy.addToStudy("+self.Px+",\""+ self.Px +"\")",
        "Vd2x = geompy.MakeVectorDXDYDZ("+Vd2xs+")",
        ])    
        

    #---------------------------------------------------------------------------------------------------------------
    def Ajouter_Pc(self,A,nom,lien) :
        
        L=float(A[0])
        Vd2=VectRatio(self.Vd2x,L)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd2]])  
        
        self.iDebutTUYAU=True
        self.nP += 1
        self.Px = "Pn_"+str(self.nP)
        if nom!="": self.Px=nom
        VPxs =  VectString2(self.VPx)        

        self.DicP[self.Px] = [[self.Vd1x0,self.Vd2x0],self.Secx,self.VPx,"",self.model,"",1,self.Temp,self.Press]     
        CodeAppend(self.CodeS,[
        "#",
        self.Px+"= geompy.MakeVertex("+VPxs+")",
        "geompy.addToStudy("+self.Px+",\""+ self.Px +"\")",
        ]) 
          
           
    #---------------------------------------------------------------------------
    def Ajouter_PF(self,A,nom,lien):
        self.Supportx="PF"
        if nom=="":nom=self.Px
        self.LesSupports.append(["PF",A,nom,self.repere]) 
        self.Ajouter_Seisme()
        self.Supportx=""
        


#    #---------------------------------------------------------------------------
#    def Ajouter_Pipe(self,V):
#        #prec : nature de  l'élément précédent
#        
#        [R,e] = self.Secx  
#        self.Secxs = VectString2(self.Secx)
#        
#        if self.model == "BARRE" : n=1
#        else: n=8
#       
#        CodeAppend(self.CodeS,[

#        "  CercleExt = geompy.MakeCircle(Px,Vd2x0,R)",
#        "  Liste.append([CercleExt ,\"CercleExt\"])",
#        "  if R>e:",
#        "      CercleInt = geompy.MakeCircle(Px,Vd2x0,R-e)",
#        "      Liste.append([CercleInt ,\"CercleInt\"])",
#        
#        "      S = geompy.MakeFaceWires([CercleExt, CercleInt], 1)",
#        "      Liste.append([S ,\"S\"])",

#        "  else:",
#        "      S = geompy.MakeFaceWires([CercleExt], 1)",
#        "      Liste.append([S ,\"S\"])",

#        "  Pipe = geompy.MakePipe( S ,V)",
#        "  Pipe.SetColor(SALOMEDS.Color("+CouleurTube+"))",
#        "  Pipe_id=geompy.addToStudy(Pipe,\""+ V +"\")",
#        "  List_id.append(Pipe_id)",
#    #    "  gg.createAndDisplayGO(Pipe_id)",
#    #    "  gg.setDisplayMode(Pipe_id,1)",

#        "  for x in Liste :",
#        "     geompy.addToStudyInFather(Pipe,x[0],x[1])",

#        "  #   Maillage  ",
#        "  PipeM = smesh.Mesh("+ V +")",
#        "  Decoupage = PipeM.Segment()",
#        "  Decoupage.NumberOfSegments("+str(n)+")",
#    #    "  Type = Decoupage.LocalLength(R/2)",
#    #    "  Type.SetPrecision(R/10),",
#        ]) 
#        
#        if self.iQUAD:
#            CodeAppend(self.CodeS,[
#            "  Quadratic_Mesh = Decoupage.QuadraticMesh()",
#            ])
#        
#        CodeAppend(self.CodeS,[
#        "  smesh.SetName(PipeM,'"+V+"')",
#        "  PipeM.Compute()",
#        "  "+V+"M=PipeM",
#        "  PipeM.GroupOnGeom("+self.Px+")",
#        "  PipeM.GroupOnGeom("+Pn+")",
#        "  PipeM.GroupOnGeom("+V+")",
#        
#        "except:",
#        "  ERREUR=True",
#        "  print (\"   =>ERREUR!\")",
#        "  for x in Liste :",
#        "     geompy.addToStudy(x[0],x[1])",
#        "  gg.setDisplayMode(O_id,0)",

#        ])

#        # Connexion 3D-TUBE si le morceau précédent était 3D
#        
#        if self.Last != [] :
#            [P0,noma,self.Vd2x0,Liaison,modela]=self.Last 
#            if modela == "3D":

#                Vd2x0s = VectString2(self.Vd2x0)
#                
#                if self.Px[0:2]=="Pn" : 
#                    indi = "1"
#                else:
#                    indi = "p"
#            
#                nomS = noma+"S"+indi  
#                    
#                CodeAppend(self.CodeS,[
#                "try:",
#                "  Px = "+P0,
#                "  P = geompy.MakeVertexWithRef(Px,"+Vd2x0s+")",
#                "  Vd2x0 = geompy.MakeVector(Px,P)",
#                "  LS1 = geompy.GetShapesOnPlane("+noma+",geompy.ShapeType[\"FACE\"],Vd2x0,GEOM.ST_ON)",
#                "  S1 = geompy.MakeCompound(LS1)",
#                "  geompy.addToStudy(S1,\""+nomS+"\")",
#                 
#                "  filter = smesh.GetFilter(smesh.FACE, smesh.FT_BelongToGeom, S1)",
#                "  ids = "+noma+"M.GetIdsFromFilter(filter)",
#                "  "+noma+"M.MakeGroupByIds(\""+nomS+"\",smesh.FACE,ids)",  
#                "except:",
#                "  print \"Ajouter_Pipe : Erreur connexion 3D-POUTRE\"",
#                ])        
#            
#            
#                xAM =  TrouverLigne(self.CodeA,"#MODELISATION")
#                CodeInsertI(self.CodeA,xAM,1,[
#                "_F(",
#                "GROUP_MA=('"+nomS+"'),",
#                "PHENOMENE='MECANIQUE',",
#                "MODELISATION='3D',",
#                "),",
#                ])
#                # Affectation des matériaux",
#                xAm =  TrouverLigne(self.CodeA,"#AFFE_MATERIAU")
#                CodeInsertI(self.CodeA,xAm,1,[
#                "_F(",
#                "GROUP_MA=('"+nomS+"'),",
#                "MATER="+self.matx+",",
#                "),",
#                ])
#                
#                # Définition des liaisons 3D-TUBE",
#                xL3D=TrouverLigne(self.CodeA,"#LIAISON_3D_POUTRE")
#                CodeInsertI(self.CodeA,xL3D,1,[
#                "_F(",
#                "OPTION='3D_POU',",
#                "GROUP_MA_1 ='"+nomS+"',",
#                "GROUP_NO_2 ='"+self.Px+"',",
#                "),",
#                ])  
#            
#        # Force linéique constante liée  au contenu
#        FZ = -math.pi*(R-e)*(R-e)*self.RhoV*self.Vg[2]
#        
#        #--------------------------------
#        # Déclaration des parties POU_D_T

#        mod = V[0:3]
#         
#        if mod == "TUB":
#        
#            self.LesTUBEs.append(V)
#            self.LesTUBEs_is.append(V)
#            self.LesVs_iMat.append(V)

#            
#        elif mod =="COU":

#            self.LesTUBEs.append(V)
#            self.LesTUBEs_is.append(V)
#            self.LesVs_iMat.append(V)
#            

#        elif mod =="CAB":
#        
#            LCable.append(V)

#            xAM =  TrouverLigne(self.CodeA,"#MODELISATION")
#            CodeInsertI(self.CodeA,xAM ,1,[
#            "_F(",
#            "GROUP_MA=('"+ V + "'),",
#            "PHENOMENE='MECANIQUE',",
#            "MODELISATION='CABLE',",
#            "),",
#            ])
#            
#            xSf =  TrouverLigne(self.CodeA,"#SECTION_CABLE")
#            CodeInsertI(self.CodeA,xSf,1,[
#            "_F(",
#            "GROUP_MA=('" + V +"'),",
#            "N_INIT=10.0,",        
#            "SECTION = "+str(math.pi*R*R)+",",
#            "),",
#            ])


#        elif mod =="BAR":

#            xAM =  TrouverLigne(self.CodeA,"#MODELISATION")
#            CodeInsertI(self.CodeA,xAM ,1,[
#            "_F(",
#            "GROUP_MA=('"+ V + "'),",
#            "PHENOMENE='MECANIQUE',",
#            "MODELISATION='BARRE',",
#            "),",
#            ])
#            
#            xSf =  TrouverLigne(self.CodeA,"#SECTION_BARRE")
#            CodeInsertI(self.CodeA,xSf,1,[
#            "_F(",
#            "GROUP_MA=('" + V +"'),",
#            "SECTION ='CERCLE',",
#            "CARA=('R','EP',),",
#            "VALE=("+ self.Secxs +"),",
#            "),",
#            ])
#            


#        if self.iTemp :

#            xCA =  TrouverLigne(self.CodeA,"#CHAMP_TEMP")
#            CodeInsertI(self.CodeA,xCA,2,[
#            "_F(",
#            "GROUP_MA=('" + V +"'),",
#            "NOM_CMP='TEMP',",
#            "VALE="+str(self.Temp)+",",
#            "),",
#            ])    


    #---------------------------------------------------------------------------
    def Ajouter_Piq(self,A,nom,lien) :
        if self.model=="3D":
            self.Ajouter_Piq_3D(A,nom,lien)
        else:
            self.Ajouter_Piq_1D(A,nom,lien)
            

    #---------------------------------------------------------------------------
    """
    Les valeurs de A sont : (Rp,ep,ad1x,ad2x,rc,n)
        Rp  :   rayon du piquage
        ep  :   épaisseur du piquage
        rc   :   rayon de courbure du joint de soudure
        ad1 :   1er angle dihèdre 
        ad2 :   2ème angle dihèdre pour des piquages non perpendiculaire
        n   :   nombre d'éléménts dans l'épaisseur 
        
    Nom peut être une liste simple ou une liste de 2 valeurs.

    AFAIRE : Le partionnement plante pour certaines valeurs Rc=L/8  Rp=L/10
    """
    def Ajouter_Piq_3D(self,A,nom,lien):

        # RECUPERATION DES INFORMATIONS
        [Rp,ep,ad,bd,rc,n] =  ConvNFloat(A,6)    
        if n==0 : n=1
        
        # INCREMENTATION
        self.nP +=1
       
        # DEFINITION DES VARIABLES
        [Rc,ec]=self.Secx
        SecPiq=[Rp,ep]
        Piq3D = "Pi3D" + str(self.nP)

        Pn = "Pn_"+str(self.nP)  
        Pm = "Pm_"+str(self.nP)
        Pr = "Pr_"+str(self.nP)
        
        
        Pp = "Pn_"+str(self.nP)
        if nom!="":  Pp="Pn_"+nom

        Vxm = "Vxm_"+str(self.nP)
        Vm1 = "Vm1_"+str(self.nP)
        Vmr = "Vmr_"+str(self.nP)
        Vrp = "Vrp_"+str(self.nP)

        Lc0 = Kpiq_c*(Rp+rc)
        Lp0 = Kpiq_p*Rp

        
        # Vecteur permettant de déterminer la position du point Pn sur le collecteur
        Vd2 = VectRatio(self.Vd2x,Lc0)    
        Vd2s = VectString2(Vd2)

        # Vecteur permettant de déterminer la position du point P2 sur le piquage
        Vd3x =  VectDih(Rc,self.Vd1x,self.Vd2x,ad,bd)
        Vd3s = VectString2(Vd3x)
        
        Vd4x = ProdVect(self.Vd2x,Vd3x)
        Vd4x = VectRatio(Vd4x,Rc)
        Vd4s = VectString2(Vd4x)

        Vd4 = VectRatio(Vd4x,(Rc)/1.414)    
        Vd2 = VectRatio(self.Vd2x,-(Rc)/1.414)  
        Vd5x = AddVect([[1,Vd4],[1,Vd2]]) 
        Vd5s = VectString2(Vd5x)
        
        Vd4 = VectRatio(Vd4x,(Rc)/1.414)    
        Vd3 = VectRatio(Vd3x,(Rc)/1.414)  
        Vd6x = AddVect([[1,Vd4],[1,Vd3]]) 
        Vd6s = VectString2(Vd6x)   
        
        Vd7x = AddVect([[1,Vd5x],[1,Vd3x]]) 
        Vd7s = VectString2(Vd7x)     

        Vd4 = VectRatio(Vd4x,(Rc)/1.414)    
        Vd2 = VectRatio(self.Vd2x,(Rc)/1.414)  
        Vd8x = AddVect([[1,Vd4],[1,Vd2]]) 
        Vd8s = VectString2(Vd8x)    
        
        #Position des nouveaux points
        VPp =  AddVect([[1,self.VPx],[1,self.Vd2x],[(Lp0+Rc)/Rc,Vd3x]]) 
        self.VPx =  AddVect([[1,self.VPx],[2,self.Vd2x]]) 
         
        # Infos sur les nouveaux points
        SIFp=2.1
        self.DicP[Pp] =  [[self.Vd2x,Vd3x],SecPiq,VPp,Piq3D,"3D","",self.Temp,self.Press] 
        self.Ajouter_Liaison(lien)
        self.DicP[Pn] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,Piq3D,"3D","",self.SIF,self.Temp,self.Press]    
         
        CodeAppend(self.CodeS,[
        "try:",
        "  Liste=[]",
        # Definition des variables  
        "  Rp = "+str(Rp),
        "  ep = "+str(ep),
        "  Rc = "+str(Rc),
        "  ec = "+str(ec),
        "  rc = "+str(rc),
        "  Kpiq_c = "+str(Kpiq_c),
        "  Kpiq_p = "+str(Kpiq_p),
        "  Rx = Rp/Rc",
        "  Rx0 = 0.75",
        "  Lc0 = Kpiq_c*(Rp+rc)",
        "  Lp0 = Kpiq_p*Rp",
        "  emax = max(ec,ep)",
        "  emin = min(ec,ep)",
        # Coefficients géométriques  
        # Positionnement du point milieu au niveau de la soudure
        "  kj = 0.35",
        # Pour le partitionnement en biais
        "  if Rx < 0.5 :",
        "    kb = 2",
        "  else:",
        "    kb = -2.8*Rx + 3.4",
        # Rapport des rayons de courbures entre Pi3D et Pi3Di
        "  kfi = 1", 
        # Coefficients de recherche   
        "  ki = 2",    
        # Création d'un piquage (maillable en réglé)
        "  Px = " +self.Px,
        "  Liste.append([Px,\""+self.Px+"\"])",
        
        "  Pm =  geompy.MakeVertexWithRef(Px,"+Vd2s+")",
        "  Liste.append([Pm,\"Pm\"])",
        
        "  "+Pn+" =  geompy.MakeVertexWithRef(Pm,"+Vd2s+")",
        "  Pn ="+Pn,
        "  Liste.append([Pn,\"Pn\"])",    
        
        "  Vd2x = geompy.MakeVector(Pm,Pn)", 
        "  Vd2xo = geompy.MakeVector(Pn,Pm)", 
        "  Liste.append([Vd2x,\"Vd2x\"])",    
            
        "  "+Pr+" =  geompy.MakeVertexWithRef(Pm,"+Vd3s+")",
        "  Pr ="+Pr,
        "  Liste.append([Pr,\"Pr\"])",    
        
        "  Vd3x = geompy.MakeVector(Pm,Pr)", 
        "  Vd3xo = geompy.MakeVector(Pr,Pm)", 
        "  Liste.append([Vd3x,\"Vd3x\"])",
        
        "  P4 =  geompy.MakeVertexWithRef(Pm,"+Vd4s+")",
        "  Liste.append([P4,\"P4\"])",   
        
        "  Vd4x = geompy.MakeVector(Pm,P4)", 
        "  Vd4xo = geompy.MakeVector(P4,Pm)", 
        "  Liste.append([Vd4x,\"Vd4x\"])",

        "  P5 =  geompy.MakeVertexWithRef(Pm,"+Vd5s+")",
        "  Vd5x = geompy.MakeVector(Pm,P5)", 
        "  Liste.append([Vd5x,\"Vd5x\"])",    
        
        "  P6 =  geompy.MakeVertexWithRef(Pm,"+Vd6s+")",
        "  Vd6x = geompy.MakeVector(Pm,P6)", 
        "  Liste.append([Vd6x,\"Vd6x\"])",   
        
        "  P7 =  geompy.MakeVertexWithRef(Pm,"+Vd7s+")",
        "  Vd7x = geompy.MakeVector(Pm,P7)", 
        "  Liste.append([Vd7x,\"Vd7x\"])", 

        "  P8 =  geompy.MakeVertexWithRef(Pm,"+Vd8s+")",
        "  Vd8x = geompy.MakeVector(Pm,P8)", 
        "  Liste.append([Vd8x,\"Vd8x\"])", 
        
        "  "+Pp+" = geompy.MakeTranslationVectorDistance(Pm,Vd3x,Rc+Lp0)",
        "  Pp = " +Pp,
        "  Liste.append([Pp,\"Pp\"])",

        "  Plan0 = geompy.MakePlane(Pm,Vd8x,Rc*Kpiq_c*10)",
        "  Liste.append([Plan0,\"Plan0\"]) ",   

        # Collecteur   
        "  Px3 = geompy.MakeTranslationVectorDistance(Px,Vd3x,Rc-ec/2)", 
        "  Liste.append([Px3,\"Px3\"])",
        
        "  Px3_ = geompy.MakeTranslationVectorDistance(Px,Vd3x,-(Rc-ec/2))",  
        "  Liste.append([Px3_,\"Px3_\"])",
        
        "  Pm3 = geompy.MakeTranslationVectorDistance(Pm,Vd3x,Rc-ec/2)", 
        "  Liste.append([Pm3,\"Pm3\"])",
        
        "  Px4 = geompy.MakeTranslationVectorDistance(Px,Vd4x,Rc-ec/2)", 
        "  Liste.append([Px4,\"Px4\"])",
        
        "  Pm4 = geompy.MakeTranslationVectorDistance(Pm,Vd4x,Rc-ec/2)", 
        "  Liste.append([Pm4,\"Pm4\"])",

        "  Vx3_ = geompy.MakeVector(Px,Px3_)",    
        #-----
        "  Cer = geompy.MakeCircle(Px,Vd2x,Rc)",
        "  Sur = geompy.MakeFaceWires([Cer], 1)",
        "  Col1 = geompy.MakePrismVecH(Sur, Vd2x, 2*Lc0)",
        "  Liste.append([Col1,\"Col1\"])",
        #-----
        "  Cer = geompy.MakeCircle(Px,Vd2x,Rc+rc/3)",
        "  Sur = geompy.MakeFaceWires([Cer], 1)",
        "  Cole = geompy.MakePrismVecH(Sur, Vd2x, 2*Lc0)",
        "  Liste.append([Cole,\"Cole\"])",
        #-----
        "  Cer = geompy.MakeCircle(Px,Vd2x,Rc-ec)",
        "  Sur = geompy.MakeFaceWires([Cer], 1)",
        "  Coli = geompy.MakePrismVecH(Sur, Vd2x, 2*Lc0)",
        "  Liste.append([Coli,\"Coli\"])",    
        # Piquage
        "  Cer = geompy.MakeCircle(Pm,Vd3x,Rp)",
        "  Sur = geompy.MakeFaceWires([Cer], 1)",
        "  Piq1 = geompy.MakePrismVecH(Sur, Vd3x, Rc+Lp0)",
        "  Liste.append([Piq1,\"Piq1\"])",
        #-----
        "  Cer = geompy.MakeCircle(Pm,Vd3x,Rp-ep)",
        "  Sur = geompy.MakeFaceWires([Cer], 1)",
        "  Piqi = geompy.MakePrismVecH(Sur, Vd3x, Rc+Lp0)",
        "  Liste.append([Piqi,\"Piqi\"])",
        #-----  
        "  Cer = geompy.MakeCircle(Pm,Vd3x,Rp+rc/3)",
        "  Sur = geompy.MakeFaceWires([Cer], 1)",
        "  Piqe = geompy.MakePrismVecH(Sur, Vd3x, Rc+Lp0)",
        "  Liste.append([Piqe,\"Piqe\"])",      
        #-----  
        "  Piq3D1 = geompy.MakeFuse(Col1,Piq1)",
        "  Liste.append([Piq3D1,\"Piq3D1\"])",
        
        "  Piq3Di = geompy.MakeFuse(Coli,Piqi)",
        "  Liste.append([Piq3Di,\"Piq3Di\"])",
        
        "  Piq3De = geompy.MakeFuse(Cole,Piqe)",
        "  geompy.addToStudy(Piq3De,\"Piq3de\")",
        
        "  Piq3D = geompy.MakeCut(Piq3D1,Piq3Di)",
        "  Liste.append([Piq3D,\"Piq3D\"])",
        "  Piq3Dio = geompy.MakeCopy(Piq3Di)",


    #   0 :  Partitionnement des differents volumes utilises
        "  print \"0 : Partitionnement des differents volumes utilises => \",",

        "  Plan1 = geompy.MakePlane(Pm,Vd2x,Rc*Kpiq_c*10)",
        "  Liste.append([Plan1,\"Plan1\"]) ",   
        
        "  Plan2 = geompy.MakePlane(Pm,Vd4x,Rc*Kpiq_c*10)",
        "  Liste.append([Plan2,\"Plan2\"]) " ,

        "  Piq3Dx = geompy.MakeHalfPartition(      Piq3D,      Plan1)",
        "  Piq3Dx = geompy.GetShapesNearPoint(     Piq3Dx,     Px,geompy.ShapeType[\"SOLID\"],1)",
        "  Liste.append([                      Piq3Dx,     \"Piq3Dx\"]) ",
        
        "  Piq3Dx = geompy.MakeHalfPartition(      Piq3Dx,     Plan2)",
        "  Piq3Dx = geompy.GetShapesNearPoint(     Piq3Dx,     P4,geompy.ShapeType[\"SOLID\"],1)",
        "  Liste.append([                      Piq3Dx,     \"Piq3Dx\"]) ",
           
        "  Piq3Dex = geompy.MakeHalfPartition(     Piq3De,     Plan1)",
        "  Piq3Dex = geompy.GetShapesNearPoint(    Piq3Dex,    Px,geompy.ShapeType[\"SOLID\"],1)",
        "  Piq3Dex = geompy.MakeHalfPartition(     Piq3Dex,    Plan2)",
        "  Piq3Dex = geompy.GetShapesNearPoint(    Piq3Dex,    P4,geompy.ShapeType[\"SOLID\"],1)",
        "  Liste.append([                      Piq3Dex,    \"Piq3Dex\"]) ",
        
        "  print \"OK\"",  
        
    # 1 - Découpage du collecteur en 2 parties: Celle autour du piquage et le reste      
        "  print \"1 : Partionnement du cylindre en 2, celle autour du piquage et le reste => \",",
        
        "  V1 = geompy.GetShapesNearPoint(Piq3Dx,P4,geompy.ShapeType[\"EDGE\"],1)",   
        
        "  p1 = geompy.GetShapesNearPoint(V1,Pr,geompy.ShapeType[\"VERTEX\"],1)",
        "  Liste.append([p1,\"p1\"])",    
        
        "  p1a = geompy.MakeScaleTransform(p1,Pm,(Rc-ec)/Rc)",
        "  Liste.append([p1a,\"p1a\"])",
        
        "  K = (Kpiq_c  - 0.90 + 0.40/(12*Rx+1))",
        "  a1_1 = math.asin(Rx)",
        "  a1_2 =K*Rx*3", 
        "  a1_3 = a1_1 + a1_2", 

        "  p1b = geompy.MakeRotation(Pr,Vd2x,a1_3)",
        "  Liste.append([p1b,\"p1b\"]) ", 

        "  p1c = geompy.MakeTranslationVectorDistance(p1b,Vd2x,-Lc0)",
        "  Liste.append([p1c,\"p1c\"]) ",  

        "  plan0 = geompy.MakePlaneThreePnt(Px,Pm,p1c,Rc*Kpiq_c*10)",
        
        "  if Rx < Rx0:",
        
        "    print \"Droit :\",",
        
        "    Piq3Dxp = geompy.MakeHalfPartition(Piq3Dx,plan0)",
        "    Liste.append([Piq3Dxp,\"Piq3Dxp\"]) ",  

        "    p1f = geompy.MakeRotation(Pr,Vd2x,(a1_1+math.pi)/2)",
        "    Liste.append([p1f,\"p1f\"]) ", 

        "    Piq3Dx = geompy.GetShapesNearPoint(Piq3Dxp,Pr,geompy.ShapeType[\"SOLID\"],1)",
        "    Liste.append([Piq3Dx,\"Piq3Dx\"]),", 
        
        "    Piq3Dx_2 = geompy.GetShapesNearPoint(Piq3Dxp,p1f,geompy.ShapeType[\"SOLID\"],1)",
        "    Liste.append([Piq3Dx_2,\"Piq3Dx_2\"]) ",

        "    try:",
        "      Piq3Dx_2 = geompy.RemoveExtraEdges(Piq3Dx_2, True)",
        "      Liste.append([Piq3Dx_2,\"Piq3Dx_2\"]) ",  
        "    except:",
        "      pass",
        
        "    print \"OK\",",  
        #-------------------
        "  print \" - Incliné :\", ", 
        
        "  a1_4 = K*Rx", 
        "  a1_5 = a1_1 + a1_4",    
      
        "  p1d = geompy.MakeRotation(Pr,Vd2x,a1_5)",
        "  Liste.append([p1d,\"p1d\"]) ",  
        
        "  p1e = geompy.MakeTranslationVectorDistance(Px,Vd3x,-kb*Rc)",
        "  Liste.append([p1d,\"p1d\"]) ",  
          
        "  p1f = geompy.MakeTranslationVectorDistance(Pm,Vd3x,-kb*Rc)",   
        "  Liste.append([p1e,\"p1e\"]) ",
          
        "  plan1 = geompy.MakePlaneThreePnt(p1d,p1e,p1f,Rc*Kpiq_c*10)",
        
        "  Piq3Dxp = geompy.MakeHalfPartition(Piq3Dx,plan1)",
        "  Liste.append([Piq3Dxp,\"Piq3Dxp\"]) ", 
        
        "  Piq3Dx = geompy.GetShapesNearPoint(Piq3Dxp,Pr,geompy.ShapeType[\"SOLID\"],1)",
        "  Liste.append([Piq3Dx,\"Piq3Dx\"]),",    

        "  Piq3Dx_3 = geompy.GetShapesNearPoint(Piq3Dxp,p1f,geompy.ShapeType[\"SOLID\"],1)",
        "  Liste.append([Piq3Dx_3,\"Piq3Dx_3\"]) ", 
        
        "  try:",
        "    Piq3Dx_3 = geompy.RemoveExtraEdges(Piq3Dx_3, True)",
        "    Liste.append([Piq3Dx_3,\"Piq3Dx_3\"]) ",   
        "  except:",
        "    pass",
        
        "  a1_6 = (a1_3 + a1_5)/2", 
        
        "  p1g = geompy.MakeRotation(Pr,Vd2x,a1_6)",
        "  Liste.append([p1g,\"p1g\"]) ",       
        
        "  print \"OK\"",   
      
        # 2 - Création de la soudure/jonction sur Piq3Dx et Piq3Dix et Pid3De

        "  print \"2 : Creation des soudures de rayon de courbure rc => \",",
        
            # Création de la soudure/jonction sur Piq3Dx  
        "  a2_1 = math.asin(Rx)",
        "  z1 = Rp/math.tan(a2_1)",
      
        "  p2b_1 = geompy.MakeTranslationVectorDistance(Pm,Vd3x,(Rc+z1)/2)",
        "  Liste.append([p2b_1,\"p2b_1\"]) ",  
        
        "  p2b_2 = geompy.MakeTranslationVectorDistance(p2b_1,Vd5x,Rp)",
        "  Liste.append([p2b_2,\"p2b_2\"]) ",      
        
        "  E2a = geompy.GetShapesNearPoint(Piq3Dx,p2b_2,geompy.ShapeType[\"EDGE\"],1)", 
        "  Liste.append([E2a,\"E2a\"])", 
        
        "  ide = geompy.GetSubShapeID(Piq3Dx,E2a)",
        "  Piq3Dx_ = geompy.MakeCopy(Piq3Dx)",    
        "  Piq3Dx = geompy.MakeFillet( Piq3Dx ,rc, geompy.ShapeType[\"EDGE\"], [ide])",
        "  Liste.append([Piq3Dx,\"Piq3Dx\"]),",

            # Création du modèle géométrique qui sera affiché
        "  E2ai = geompy.GetShapesNearPoint(Piq3D,p2b_2,geompy.ShapeType[\"EDGE\"],1)", 
        "  Liste.append([E2ai,\"E2ai\"])", 
        
        "  ide = geompy.GetSubShapeID(Piq3D,E2ai)",
        "  Piq3D = geompy.MakeFillet( Piq3D ,rc, geompy.ShapeType[\"EDGE\"], [ide])",
        "  "+Piq3D+"=Piq3D",
        "  Piq3D_id = geompy.addToStudy(Piq3D,\""+Piq3D+"\")",      
            
        "  gg.createAndDisplayGO(Piq3D_id)",
        "  gg.setDisplayMode(Piq3D_id,1)",     
     
        "  a2 = math.asin((Rp-ep)/(Rc-ec))",
        "  z2 = (Rp-ep)/math.tan(a2)",
      
        "  p2c_1 = geompy.MakeTranslationVectorDistance(Pm,Vd3x,z2)",
        "  Liste.append([p2c_1,\"p2c_1\"]) ",  
        
        "  p2c_2 = geompy.MakeTranslationVectorDistance(p2c_1,Vd5x,Rp-ep)",
        "  Liste.append([p2c_2,\"p2c_2\"]) ",    

        "  E2c = geompy.GetEdgeNearPoint(Piq3Dx,p2c_2 )",
        "  Liste.append([E2c,\"E2c\"])",     
          
        "  print \"OK\"", 

        #  3 - Partionnement du piquage en 2 parties : Celle sur le collecteur et celle du  piquage proprement dit    
        "  print \"3 : Partionnement du piquage en Col et Piq => \",",

        "  p3b = geompy.MakeTranslationVectorDistance(p2b_2,Vd3x,rc)",
        "  Liste.append([p3b,\"p3b\"])",     
        
        "  E3a = geompy.GetShapesNearPoint(Piq3Dx,p3b,geompy.ShapeType[\"EDGE\"],1)", 
        "  Liste.append([E3a,\"E3a\"])", 
        
        "  p3c = geompy.MakeTranslationVectorDistance(p2b_2,Vd2x,-2*rc)",
        "  Liste.append([p3c,\"p3c\"])",

        "  E3b = geompy.GetShapesNearPoint(Piq3Dx,p3c,geompy.ShapeType[\"EDGE\"],1)", 
        "  Liste.append([E3b,\"E3b\"])",    
        
        "  p3d_1 = geompy.MakeVertexOnCurve(E3a,0.0)",     
        "  p3d_2 = geompy.MakeVertexOnCurve(E3b,0.0)",  
        "  V = geompy.MakeVector(p3d_1, p3d_2)",
        "  p3d_3 = geompy.MakeVertexOnCurve(V,0.5)",  
        "  Liste.append([p3d_3,\"p3d_3\"])",      
        
        "  p3e_1 = geompy.MakeVertexOnCurve(E3a,0.25)",      
        "  p3e_2 = geompy.MakeVertexOnCurve(E3b,0.25)",  
        "  V = geompy.MakeVector(p3e_1, p3e_2)",
        "  p3e_3 = geompy.MakeVertexOnCurve(V,0.5)",  
        "  Liste.append([p3e_3,\"p3e_3\"])",   
        
        "  p3f_1 = geompy.MakeVertexOnCurve(E3a,0.5)",      
        "  p3f_2 = geompy.MakeVertexOnCurve(E3b,0.5)",  
        "  V = geompy.MakeVector(p3f_1, p3f_2)",
        "  p3f_3 = geompy.MakeVertexOnCurve(V,0.5)",  
        "  Liste.append([p3f_3,\"p3f_3\"])",     
        
        "  p3g_1 = geompy.MakeVertexOnCurve(E3a,0.75)",      
        "  p3g_2 = geompy.MakeVertexOnCurve(E3b,0.75)",   
        "  V = geompy.MakeVector(p3g_1, p3g_2)",
        "  p3g_3 = geompy.MakeVertexOnCurve(V,0.5)",  
        "  Liste.append([p3g_3,\"p3g_3\"])",
        
        "  p3h_1 = geompy.MakeVertexOnCurve(E3a,1)",  
        "  Liste.append([p3h_1,\"p3h_1\"])",  
         
        "  p3h_2 = geompy.MakeVertexOnCurve(E3b,1)",
        "  Liste.append([p3h_2,\"p3h_2\"])",
        
        "  V = geompy.MakeVector(p3h_1, p3h_2)",
        
        "  p3h_3 = geompy.MakeVertexOnCurve(V,0.5)",  
        "  Liste.append([p3h_3,\"p3h_3\"])",      
        
        "  E3c = geompy.MakeInterpol([p3d_3,p3e_3,p3f_3,p3g_3,p3h_3])",
        "  Liste.append([E3c,\"E3c\"])", 
        
        "  S3c = geompy.MakeQuad2Edges(E3c,E2c)", 
        "  Liste.append([S3c,\"S3c\"])",    

        "  Piq3Dx_ = geompy.MakeCopy(Piq3Dx)",
        "  Piq3Dx = geompy.MakePartition([Piq3Dx],[S3c],KeepNonlimitShapes=0)",
        
        "  Piq = geompy.GetShapesNearPoint(Piq3Dx,Pp,geompy.ShapeType[\"SOLID\"],1)",
        "  Col = geompy.GetShapesNearPoint(Piq3Dx,Px,geompy.ShapeType[\"SOLID\"],1)",    

        "  Col = geompy.ProcessShape(Col, [\"FixShape\", \"FixFaceSize\", \"DropSmallEdges\",",
        "                           \"SameParameter\"], [\"FixShape.Tolerance3d\", \"FixShape.MaxTolerance3d\",",
        "                           \"FixFaceSize.Tolerance\", \"DropSmallEdges.Tolerance3d\", \"SameParameter.Tolerance3d\"],",
        "                          [\"1e-07\", \"1\", \"0.05\", \"0.05\", \"1e-07\"])",
        "  Liste.append([Col,\"Col\"])",       

        "  Piq = geompy.ProcessShape(Piq, [\"FixShape\", \"FixFaceSize\", \"DropSmallEdges\",",
        "                           \"SameParameter\"], [\"FixShape.Tolerance3d\", \"FixShape.MaxTolerance3d\",",
        "                           \"FixFaceSize.Tolerance\", \"DropSmallEdges.Tolerance3d\", \"SameParameter.Tolerance3d\"],",
        "                          [\"1e-07\", \"1\", \"0.05\", \"0.05\", \"1e-07\"])",
        "  Liste.append([Piq,\"Piq\"])",   
        "  print \"OK\"", 

    #    # 4 - Partitionnement de Col  en zone soudure et zone non soudure
        "  print \"4 : Partionnement de la soudure de Col => \",",
        
        "  p4a_1 = geompy.MakeRotation(Pr,Vd2x,a1_1)",
        "  Liste.append([p4a_1,\"p4a_1\"])",   
        
        "  p4a_2 = geompy.GetShapesNearPoint(Col,p4a_1,geompy.ShapeType[\"VERTEX\"],1)", 
        "  Liste.append([p4a_2,\"p4a_2\"])",   

        "  b1 = math.asin((Rp-ep)/(Rc-ec))",
        
        "  p4b_1 = geompy.MakeTranslationVectorDistance(Pm,Vd3x,Rc-ec)",
        "  Liste.append([p4b_1,\"p4b_1\"])", 

        "  p4b_2 = geompy.MakeRotation(p4b_1,Vd2x,b1)",
        "  Liste.append([p4b_2,\"p4b_2\"])",     

        "  p4b_3 = geompy.GetShapesNearPoint(Col,p4b_2,geompy.ShapeType[\"VERTEX\"],1)", 
        "  Liste.append([p4b_3,\"p4b_3\"])",         
        
        "  V4b = geompy.MakeVector(p4a_2, p4b_2)", 
        "  Liste.append([V4b,\"V4b\"])", 

        "  V4c = geompy.MakeVector(p4b_2, p4a_2)", 
        "  Liste.append([V4c,\"V4c\"])",     
      
        "  a4_1 = geompy.GetAngle(V4c, Vd3x)", 
        
        "  if a4_1 > 60 :",
        "    V = geompy.MakeCopy(Vd6x)",
        "  else :",
        "    V = geompy.MakeCopy(V4c)",
          
        "  E4b = geompy.MakeTranslationVectorDistance(E3b,V,1)",
        "  Liste.append([E4b,\"E4b\"])",
         
        "  S4a = geompy.MakePrismVecH(E4b, V, -(Rc+ec))",         
        "  Liste.append([S4a,\"S4a\"])",
        
        "  Col = geompy.MakePartition([Col],[S4a],KeepNonlimitShapes=0)",
        "  Liste.append([Col,\"Col\"])",   
        
        "  print \"OK\"",
     
    #    # 5 - Partitionnement de Piq  en zone soudure et zone non soudure    
        "  print \"5 : Partionnement de la soudure de Piq => \",",      

        "  p5a = geompy.MakeTranslationVectorDistance(p2b_2,Vd3x,2*rc)",
        "  Liste.append([p5a,\"p5a\"])",      
        
        "  E5a = geompy.GetShapesNearPoint(Piq,p5a,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E5a,\"E5a\"])",   
        
        "  E5b = geompy.MakeTranslationVectorDistance(E5a,Vd5x,ec/2)",
        "  Liste.append([E5b,\"E5b\"])",   
        
        "  S5a = geompy.MakePrismVecH(E5b, Vd5x, -(Rc+ec))",         
        "  Liste.append([S5a,\"S5a\"])",
        
        "  Piq = geompy.MakePartition([Piq],[S5a],KeepNonlimitShapes=0)",
        "  Liste.append([Piq,\"Piq\"])", 
        
        "  print \"OK\"",     

    #    6 - Partitionnement de Col pour obtenir des zones maillables en règlées    
        "  print \"6 : Partitionnement de Col pour obtenir des zones maillables en regles   => \",",    
        
        "  p6a = geompy.MakeTranslationVectorDistance(p1d,Vd2x,-Lc0)",
        "  Liste.append([p6a,\"p6a\"])",   
        
        "  V6 = geompy.MakeVector(p1e,p6a)",
        "  Liste.append([V6,\"V6\"])",
        
        "  a6_1 = geompy.GetAngle(V6, Vd3x)",
        "  z6 = (Rp-ep)/math.tan(a6_1*math.pi/180)",

        "  p6b = geompy.MakeTranslationVectorDistance(p6a,V6,-ec)",    
        "  Liste.append([p6b,\"p6b\"])",
        
        "  p6c = geompy.GetShapesNearPoint(Col,p6b,geompy.ShapeType[\"VERTEX\"],1)",
        "  Liste.append([p6c,\"p6c\"])",    
        
        "  p6d = geompy.MakeVertexOnCurve(E2c,kj)",   
        "  Liste.append([p6d,\"p6d\"])",
        
        "  SP6a = geompy.MakePlaneThreePnt(p6a ,p6c ,p6d,Rc*Kpiq_c*10)",
        "  Liste.append([SP6a,\"SP6a\"])", 
        
        "  Col = geompy.MakePartition([Col],[SP6a],KeepNonlimitShapes=0)",      
        "  Liste.append([Col,\"Col\"])", 
            
        "  print \"OK\"",    
        
    #    7 - Partitionnement de Piq pour obtenir des zones maillables en règlées    
        "  print \"7 : Partitionnement de Piq pour obtenir des zones maillables en regles   => \",",    
     
        "  V7a = geompy.MakeVector(p6d,p3f_3)", 
        
        "  p7a = geompy.MakeVertexOnCurve(V7a,0.5)",   
        "  Liste.append([p7a,\"p7a\"])", 

        "  E7a = geompy.GetShapesNearPoint(Col,p7a ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E7a,\"E7a\"])", 
        
        "  p7b = geompy.GetShapesNearPoint(E7a,p3f_3,geompy.ShapeType[\"VERTEX\"],1)",
        "  Liste.append([p7b,\"p7b\"])",     
        
        "  p7c_1 = geompy.MakeTranslationVectorDistance(Pm,Vd3x,Rc+Lp0)",
        "  Liste.append([p7c_1,\"p7c_1\"])",   
        
        "  p7c_2 = geompy.MakeTranslationVectorDistance(p7c_1,Vd5x,Rp-ep/2)",
        "  Liste.append([p7c_2,\"p7c_2\"])",

        "  SP7a = geompy.MakePlaneThreePnt(p6d ,p7b ,p7c_2,Rc*Kpiq_c*10)",
        "  Liste.append([SP7a,\"SP7a\"])", 
        
        "  Piq = geompy.MakePartition([Piq],[SP7a],KeepNonlimitShapes=0)",      
        "  Liste.append([Piq,\"Piq\"])", 
            
        "  print \"OK\"",           

    #    8 - Assemblage    
        "  print \"8 : Assemblages des differentes parties   => \",",

        "  try:",
        "    Col = geompy.RemoveExtraEdges(Col, True)",
        "    Liste.append([Col,\"Col8\"])", 
        "  except:",
        "     pass",  
        
        "  try:",
        "    Piq = geompy.RemoveExtraEdges(Piq, True)",
        "    Liste.append([Piq,\"Piq8\"])", 
        "  except:",
        "     pass",
        
        "  try:",
        "    Piq3Dx_3, = geompy.RemoveExtraEdges(Piq3Dx_3, True)",
        "    Liste.append([Piq3Dx_3,\"Piq3Dx_3,\"])", 
        "  except:",
        "     pass",
        
        "  if Rx < Rx0:",    
        "    try:",
        "      Piq3Dx_2, = geompy.RemoveExtraEdges(Piq3Dx_2, True)",
        "      Liste.append([Piq3Dx_2,\"Piq3Dx_2,\"])", 
        "    except:",
        "      pass",

        "  Piq3Dx_1 = geompy.MakeCompound([Piq, Col])", 
        "  Piq3Dx_1 = geompy.MakeGlueFaces(Piq3Dx_1, 0.1)",    
        "  Liste.append([Piq3Dx_1,\"Piq3Dx_1\"])",   

        "  print \"OK\"",     
       
    #    9 - Maillage   de Piq3Dx 

        "  print \"9 : Maillage de Piq3Dx   => \"," ,    
          #------------      
        "  Piq3DxM_1 = smesh.Mesh(Piq3Dx_1)",
     
        "  Piq3DxM_1.Quadrangle()",
        
        "  Hexa_3D = smesh.CreateHypothesis('Hexa_3D')",
        "  status = Piq3DxM_1.AddHypothesis(Hexa_3D)",
        
        "  Regular_1D_1  = Piq3DxM_1.Segment()  ",
        "  Nb_Segments_1 = Regular_1D_1.NumberOfSegments(5)",
            "  Nb_Segments_1.SetDistrType( 1 )",
            "  Nb_Segments_1.SetScaleFactor( 1 )",
        "  Regular_1D_1.Propagation()", 
        
        "  print \" - \"," ,       
          #-------------      
        "  V9x_1 = geompy.MakeVector(p6a, p6c)",
        "  Liste.append([V9x_1,\"V9x_1\"])",      
        
        "  p9x_1  = geompy.MakeVertexOnCurve(V9x_1,0.5)",   
        "  Liste.append([p9x_1,\"p9x_1\"])",   
        
        "  E9x_1 = geompy.GetShapesNearPoint(Piq3Dx_1,p9x_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9x_1,\"E9x_1\"])", 
     
        "  Regular_1D_x = Piq3DxM_1.Segment(geom=E9x_1)",
        "  Nb_Segments_x = Regular_1D_x.NumberOfSegments(3)", 
            "  Nb_Segments_x.SetDistrType( 1 )",
            "  Nb_Segments_x.SetScaleFactor( 1 )",
        "  Regular_1D_x.Propagation()",

        "  print \" - \"," ,         
        #------------             
        "  p9a_2 = geompy.MakeTranslationVectorDistance(Pm,Vd3x,Rc-ec)",
        "  Liste.append([p9a_2,\"p9a_2\"])", 
        
        "  p9a_3 = geompy.MakeTranslationVectorDistance(p9a_2,Vd2x, -(Rp-ep))",
        "  Liste.append([p9a_3,\"p9a_3\"])",
        
        "  p9a_4 = geompy.MakeTranslationVectorDistance(p9a_3,Vd2x, -(Rp-ep)*0.05)",
        "  Liste.append([p9a_4,\"p9a_4\"])",
        
        "  E9a_2 = geompy.GetShapesNearPoint(Piq3Dx_1,p9a_4 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9a_2,\"E9a_2\"])",     

        "  Regular_1D_a = Piq3DxM_1.Segment(geom=E9a_2)",
        "  Nb_Segments_a = Regular_1D_a.NumberOfSegments(3)",
            "  Nb_Segments_a.SetDistrType( 1 )",
            "  Nb_Segments_a.SetScaleFactor( 1 )",
        "  Regular_1D_a.Propagation()",

        "  print \" - \"," ,          
        #------------        
        "  p9b_1 = geompy.MakeTranslationVectorDistance(p9a_3,Vd3x, ec/2)",
        "  Liste.append([p9b_1,\"p9b_1\"])",
        
        "  E9b_1 = geompy.GetShapesNearPoint(Piq3Dx_1,p9b_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9b_1,\"E9b_1\"])", 
        
        "  Regular_1D_b = Piq3DxM_1.Segment(geom=E9b_1)",
        "  Nb_Segments_b = Regular_1D_b.NumberOfSegments(3)",
            "  Nb_Segments_b.SetDistrType( 1 )",
            "  Nb_Segments_b.SetScaleFactor( 0.5 )",
        
        "  print \"  -  \"," ,        
        #------------      
        "  V9c_1 = geompy.MakeVector( p6d, p6a)",
        "  p9c_1 = geompy.MakeVertexOnCurve (V9c_1, 0.5)",
        "  Liste.append([p9c_1,\"p9c_1\"])",
        
        "  p9c_2 = geompy.MakeTranslationVectorDistance(p9c_1,Vd3x, ec/2)",
        "  Liste.append([p9c_2,\"p9c_2\"])",
        
        "  E9c_1 = geompy.GetShapesNearPoint(Piq3Dx_1,p9c_2 ,geompy.ShapeType[\"EDGE\"],ec/4)",
        "  Liste.append([E9c_1,\"E9c_1\"])",  
        
        "  p9c_3 = geompy.MakeTranslationVectorDistance(p9c_1,Vd3x, -ec/2)",
        "  Liste.append([p9c_3,\"p9c_3\"])",
        
        "  E9c_2 = geompy.GetShapesNearPoint(Piq3Dx_1,p9c_3 ,geompy.ShapeType[\"EDGE\"],ec/4)",
        "  Liste.append([E9c_2,\"E9c_2\"])",  
        
        "  E9c_3 = geompy.MakeCompound([E9c_1,E9c_2])",

        "  Regular_1D_c = Piq3DxM_1.Segment(geom=E9c_3)",
        "  Nb_Segments_c = Regular_1D_c.NumberOfSegments(5)",   
            "  Nb_Segments_c.SetDistrType( 1 )",
            "  Nb_Segments_c.SetScaleFactor( 4 )",

        "  print \" - \"," ,       
        #------------
        "  p9d_1 = geompy.MakeTranslationVectorDistance(p6a,Vd2x, Lc0/2)",
        "  Liste.append([p9d_1,\"p9d_1\"])",    
        
        "  E9d_1 = geompy.GetShapesNearPoint(Piq3Dx_1,p9d_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9d_1,\"E9d_1\"])", 
        
        "  V9d_1 = geompy.MakeVector(p6a,p6c)",
        "  Liste.append([V9d_1,\"V9d_1\"])",  
        
        "  p9d_2 = geompy.MakeTranslationVector(p9d_1,V9d_1)",
        "  Liste.append([p9d_2,\"p9d_2\"])",    

        "  E9d_2 = geompy.GetShapesNearPoint(Piq3Dx_1,p9d_2 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9d_2,\"E9d_2\"])",             
        
        "  E9d_3 = geompy.MakeCompound([E9d_1,E9d_2])",

        "  Regular_1D_d = Piq3DxM_1.Segment(geom=E9d_3)",
        "  Nb_Segments_d = Regular_1D_d.NumberOfSegments(5)",   
            "  Nb_Segments_d.SetDistrType( 1 )",
            "  Nb_Segments_d.SetScaleFactor( 2 )",
           
        "  print \" - \"," ,    
        #------------     
        "  p9e_1 = geompy.MakeTranslationVectorDistance(Pm,Vd3x, Rc + Lp0/2)",
        "  Liste.append([p9e_1,\"p9e_1\"])",    
        
        "  p9e_2 = geompy.MakeTranslationVectorDistance(p9e_1,Vd4x, Rp)",
        "  Liste.append([p9e_2,\"p9e_2\"])",   
        
        "  E9e_1 = geompy.GetShapesNearPoint(Piq3Dx_1,p9e_2 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9e_1,\"E9e_1\"])",   
        
        "  p9e_3 = geompy.MakeTranslationVectorDistance(p9e_2,Vd4x, -ep)",
        "  Liste.append([p9e_3,\"p9e_3\"])",   
        
        "  E9e_2 = geompy.GetShapesNearPoint(Piq3Dx_1,p9e_3 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9e_2,\"E9e_2\"])",   
        
        "  E9e_3 = geompy.MakeCompound([E9e_1,E9e_2])",    

        "  Regular_1D_e = Piq3DxM_1.Segment(geom=E9e_3)",
        "  Nb_Segments_e = Regular_1D_e.NumberOfSegments(5)",   
            "  Nb_Segments_e.SetDistrType( 1 )",
            "  Nb_Segments_e.SetScaleFactor( 0.5 )",
        
        "  print \" - \"," ,    
        #------------    
        "  p9g_1 = geompy.MakeTranslationVectorDistance(p4a_1,Vd2x, -Lc0)",
        "  Liste.append([p9g_1,\"p9g_1\"])",  
        
        "  E9g_1 = geompy.GetShapesNearPoint(Piq3Dx_1,p9g_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9g_1,\"E9g_1\"])", 

        "  p9g_2 = MakeScaleTransform(p9g_1,Px,(Rc-ec)/Rc)",
        "  Liste.append([p9g_2,\"p9g_2\"])",      
        
        "  E9g_2 = geompy.GetShapesNearPoint(Piq3Dx_1,p9g_2 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E9g_2,\"E9g_2\"])",            
        
        "  E9g_3 = geompy.MakeCompound([E9g_1,E9g_2])",
        "  Liste.append([E9g_3,\"E9g_3\"])",
        
        "  Regular_1D_g = Piq3DxM_1.Segment(geom=E9g_3)",
        "  Nb_Segments_g = Regular_1D_g.NumberOfSegments(5)",   
            "  Nb_Segments_g.SetDistrType( 1 )",
            "  Nb_Segments_g.SetScaleFactor( 2 )",
        
        "  print \" - \"," , 
        #------------     
        "  V9h_1 = geompy.MakeVector( p6d ,p4b_2)",
        "  Liste.append([V9h_1,\"V9h_1\"])", 
        
        "  p9h_1 = geompy.MakeVertexOnCurve (V9h_1, 0.5)",
        "  Liste.append([p9h_1,\"p9h_1\"])",
        
        "  E9h_1 = geompy.GetShapesNearPoint(Piq3Dx_1,p9h_1 ,geompy.ShapeType[\"EDGE\"],ep)",
        "  Liste.append([E9h_1,\"E9h_1\"])",  
        
        "  V9h_2 = geompy.MakeVector(p7b,p4a_2)",
        "  Liste.append([V9h_2,\"V9h_2\"])", 
        
        "  p9h_2 = geompy.MakeVertexOnCurve (V9h_2, 0.5)",
        "  Liste.append([p9h_2,\"p9h_2\"])",
        
        "  E9h_2 = geompy.GetShapesNearPoint(Piq3Dx_1,p9h_2 ,geompy.ShapeType[\"EDGE\"],ep)",
        "  Liste.append([E9h_2,\"E9h_2\"])",  
        
        "  E9h = geompy.MakeCompound([E9h_1,E9h_2])",    

        "  Regular_1D_h = Piq3DxM_1.Segment(geom=E9h)",
        "  Nb_Segments_h = Regular_1D_h.NumberOfSegments(5)",   
            "  Nb_Segments_h.SetDistrType( 1 )",
            "  Nb_Segments_h.SetScaleFactor( 1 )",
        "  Regular_1D_h.Propagation()",
              
        "  print \" - \"," , 
        #------------   
        "  E9i = geompy.GetShapesNearPoint(Piq3Dx_1,p3e_3 ,geompy.ShapeType[\"EDGE\"],rc/4)",
        "  Liste.append([E9i,\"E9i\"])",
     
        "  Regular_1D_i = Piq3DxM_1.Segment(geom=E9i)",
        "  Nb_Segments_i = Regular_1D_i.NumberOfSegments(5)", 
            "  Nb_Segments_i.SetDistrType( 1 )",
            "  Nb_Segments_i.SetScaleFactor( 2 )",

        "  print \" - \"," ,    
        #------------      
        "  Piq3DxM_1.Compute()",     
     
        "  print \" OK  \"" ,  

        
    # 10: Maillage de Piq3Dx_3,
            
        "  print \"10:  Maillage de Piq3Dx_3, = >   \"," ,       
          
        "  Piq3DxM_3 = smesh.Mesh(Piq3Dx_3)", 

        "  Piq3DxM_3.Quadrangle()",

        "  Hexa_3D_3 = smesh.CreateHypothesis('Hexa_3D')",
        "  Piq3DxM_3.AddHypothesis(Hexa_3D_3)",

        "  print \" - \"," , 
        #------------   
        "  Regular_1D_3 = Piq3DxM_3.Segment()  ",
        "  Nb_Segments_3 = Regular_1D_3.NumberOfSegments(5)",
        "  Nb_Segments_3.SetDistrType( 0 )",
        
        "  print \" - \"," ,       
        #------------  
        "  E10x_1 = geompy.GetShapesNearPoint(Piq3Dx_3,p9x_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E10x_1,\"E10x_1\"])",    
        
        "  p10x_1 = geompy.MakeTranslationVectorDistance(p9x_1,Vd2x, Lc0)",
        "  Liste.append([p10x_1,\"p10x_1\"])",     
        
        "  E10x_2 = geompy.GetShapesNearPoint(Piq3Dx_3,p10x_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E10x_2,\"E10x_2\"])",  
        
        "  E10x_3 = geompy.MakeCompound([E10x_1,E10x_2])",    
     
        "  Regular_1D_x = Piq3DxM_3.Segment(geom=E10x_3)",
        "  Nb_Segments_x = Regular_1D_x.NumberOfSegments(3)",
        "  Nb_Segments_x.SetDistrType( 0 )",
        "  if Rx > Rx0 :",
        "    Regular_1D_x.Propagation()",    

        "  print \" - \"," ,        
        #-----------	    
        "  if Rx < Rx0 :",
        "    Quadrangle_Parameters_1 = smesh.CreateHypothesis('QuadrangleParams')",
        "    Quadrangle_Parameters_1.SetQuadType( StdMeshers.QUAD_QUADRANGLE_PREF )",
        "    Piq3DxM_3.AddHypothesis(Quadrangle_Parameters_1,Piq3Dx_3,)",
        
        "    p10a_1 = MakeScaleTransform(p1b,Pm,(Rc-ec/2)/Rc)",
        "    Liste.append([p10a_1,\"p10a_1\"])",    

        "    E10a_1 = geompy.GetShapesNearPoint(Piq3Dx_3,p10a_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "    Liste.append([E10a_1,\"E10a_1\"])",   
        
        "    p10a_2 = MakeScaleTransform(p1c,Px,(Rc-ec/2)/Rc)",
        "    Liste.append([p10a_2,\"p10a_2\"])",    

        "    E10a_2 = geompy.GetShapesNearPoint(Piq3Dx_3,p10a_2 ,geompy.ShapeType[\"EDGE\"],1)",
        "    Liste.append([E10a_2,\"E10a_2\"])",     
         
        "    E10a_3 = geompy.MakeCompound([E10a_1,E10a_2])",    
     
        "    Regular_1D_a = Piq3DxM_3.Segment(geom=E10a_3)",
        "    Nb_Segments_a = Regular_1D_a.NumberOfSegments(1)",
        "    Nb_Segments_a.SetDistrType( 0 )",

        "    print \" - \"," ,         
        #-----------    
        "  E10d_1 = geompy.GetShapesNearPoint(Piq3Dx_3,p9d_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E10d_1,\"E10d_1\"])",     

        "  E10d_2 = geompy.GetShapesNearPoint(Piq3Dx_3,p9d_2 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E10d_2,\"E10d_2\"])",             
        
        "  E10d_3 = geompy.MakeCompound([E10d_1,E10d_2])",

        "  Regular_1D_d = Piq3DxM_3.Segment(geom=E10d_3)",
        "  Nb_Segments_d = Regular_1D_d.NumberOfSegments(5)",   
        "  Nb_Segments_d.SetDistrType( 1 )",
        "  Nb_Segments_d.SetScaleFactor( 2 )",
           
        "  print \" - \"," ,  
        #-----------	        
        "  isDone = Piq3DxM_3.Compute()",    
        
        "  print \" OK \"" ,  

    # 11 Maillage de Piq3Dx_2, 
        "  if Rx < Rx0:",
        
        "    print \"11:  Maillage de Piq3Dx_2, = >   \"," ,   

        "    Piq3DxM_2 = smesh.Mesh(Piq3Dx_2)", 
        "    Piq3DxM_2.Quadrangle()",
        "    Hexa_3D_2 = smesh.CreateHypothesis('Hexa_3D')",	
        "    Piq3DxM_2.AddHypothesis(Hexa_3D_2)",

        "    print \" - \"," , 
        #------------ 
        "    Regular_1D_2 = Piq3DxM_2.Segment()  ",
        "    Nb_Segments_2 = Regular_1D_2.NumberOfSegments(5)",
        "    Nb_Segments_2.SetDistrType( 0 )",
        
        "    print \" - \"," ,      
        #------------       
        "    E11a_1 = geompy.GetShapesNearPoint(Piq3Dx_2,p10a_2 ,geompy.ShapeType[\"EDGE\"],1)",
        "    Liste.append([E11a_1,\"E11a_1\"])",     
     
        "    Regular_1D_a = Piq3DxM_2.Segment(geom=E11a_1)",
        "    Nb_Segments_a = Regular_1D_a.NumberOfSegments(1)",
        "    Nb_Segments_a.SetDistrType( 0 )",
        "    Regular_1D_a.Propagation()",

        "    print \" - \"," ,     
        #------------        
        "    a11b_1 = (a1_2 +math.pi)/2",  
          
        "    p11b_1 = geompy.MakeRotation(Pr,Vd2x,a11b_1)",
        "    Liste.append([p11b_1,\"p11b_1\"]) ", 

        "    E11b_1 = geompy.GetShapesNearPoint(Piq3Dx_2,p11b_1 ,geompy.ShapeType[\"EDGE\"],1)",
        "    Liste.append([E11b_1,\"E11b_1\"])",
        
        "    Regular_1D_b = Piq3DxM_2.Segment(geom=E11b_1)",
        "    n = int(Rc*(math.pi-a1_3)/ec)",
        "    Nb_Segments_b = Regular_1D_b.NumberOfSegments(n)",
        "    Nb_Segments_b.SetDistrType( 0 )",
        "    Regular_1D_b.Propagation()",

        "    print \" - \"," ,   
        #-----------	        
        "    Piq3DxM_2.Compute()",
         
        "    print \" OK \"" ,       
        
    # 12 Concatenation  
        "  print \"12:  Concatenation = >   \"," ,  
         
        "  if Rx < Rx0:",  
        "    "+Piq3D+"M = smesh.Concatenate([Piq3DxM_1,Piq3DxM_3,Piq3DxM_2], 1, 0, 1e-05)",
        "  else:",
        "    "+Piq3D+"M = smesh.Concatenate([Piq3DxM_1,Piq3DxM_3], 1, 0, 1e-05)",

        "  print \"OK\"", 
        
    # 13:  Construction du maillage complet
        "  print \"13:  Construction du maillage complet = >   \"," , 
            
        "  print \" Plan 2 - \",",
        "  [x,y,z] = geompy.PointCoordinates(Pm)",
        "  "+Piq3D+"M.MirrorObject( "+Piq3D+"M, SMESH.AxisStruct( x,y,z,"+ Vd2s+" ), SMESH.SMESH_MeshEditor.PLANE, 1 )",
        "  print \" Plan 1 - \",",    
        "  "+Piq3D+"M.MirrorObject( "+Piq3D+"M, SMESH.AxisStruct( x,y,z,"+ Vd4s+" ), SMESH.SMESH_MeshEditor.PLANE, 1 )", 
         	
        "  smesh.SetName( "+Piq3D+"M , '"+ Piq3D+"M')",
        
        "  print \"OK\"", 
        
    # 14:  Suppression des elements coincidents  
        "  print \"14:  Suppression des elements coincidents = >   \"," , 
               
        "  coincident_nodes = "+Piq3D+"M.FindCoincidentNodes( 1e-04 )",
        "  "+Piq3D+"M.MergeNodes(coincident_nodes)",
        
        "  equal_elements = "+Piq3D+"M.FindEqualElements("+Piq3D+"M)",    
        "  "+Piq3D+"M.MergeElements(equal_elements)",        
        
        "  print \"OK\"",  
        
    # 15:  Creation des groupes de mailles  
        "  print \"15:  Creation des groupes de mailles = >   \"," , 
        
       

    #BUG : Piq3De ne doit pas être mis inFather pour pouvoir être utilisé ici.   
        "  filter = smesh.GetFilter(smesh.VOLUME, smesh.FT_BelongToGeom, Piq3De)",
        "  ids = "+Piq3D+"M.GetIdsFromFilter(filter)",
        "  "+Piq3D+"M.MakeGroupByIds(\""+Piq3D+"\",smesh.VOLUME,ids)",    

        "  print \"V : OK, \",",     

        "  print \"  => OK\"",        

        ])
      
        self.Les3Ds.append(Piq3D)
        self.LesVs_iMat.append(Piq3D)
        

        [Vdx0,Sec0,VPx0,noma,modela,Sec3Dx,SIFx,Tempx,Pressx] = self.DicP[self.Px]
        
        if modela == "TUBE":

            CodeAppend(self.CodeS,[
            #BUG : Sx ne peut être mis in Father, comme SP et Sx et le groupe volumique 
            "  Sx = geompy.GetFaceByNormale(Piq3D,Vd2xo)",
            "  "+Piq3D+"Sx = Sx",
            "  geompy.addToStudy(Sx,\""+Piq3D+"Sx\")",
             
            "  filter = smesh.GetFilter(smesh.FACE, smesh.FT_BelongToGeom, Sx)",
            "  ids = "+Piq3D+"M.GetIdsFromFilter(filter)",
            "  "+Piq3D+"M.MakeGroupByIds(\""+Piq3D+"Sx\",smesh.FACE,ids)",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#MODELISATION")

            CodeInsertI(self.CodeA,Lx,1,[
            "_F(",
            "   GROUP_MA=('" + Piq3D +"Sx'),",
            "   PHENOMENE='MECANIQUE',",
            "   MODELISATION='3D',",
            "),",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#AFFE_MATERIAU")
            CodeInsertI(self.CodeA,Lx,1,[
            "_F(",
            "   GROUP_MA=('" + Piq3D+"Sx'),",
            "   MATER="+self.matx+",",
            "),",
            ])
            
            # Définition des liaisons 3D-TUBE",
            Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_TUBE")
            CodeInsertI(self.CodeA,Lx,1,[
            "_F(",
            "   OPTION='3D_POU',",
            "   GROUP_MA_1 ='"+Piq3D+"Sx',",
            "   GROUP_NO_2 ='"+self.Px+"',",
            "),"
            ])


        CodeAppend(self.CodeS,[
        "  for x in Liste:",
        "    geompy.addToStudyInFather(Piq3D,x[0],x[1])",
        "except:",
        "  print \"Erreur avec Piq3D\"",
        "  for x in Liste:",
        "    geompy.addToStudy(x[0],x[1])",    
        
        ])
        # ENREGISTREMENT DES INFOS POUR LA SUITE   

        self.LTout.append(Piq3D)
        self.Px = Pn 



    #---------------------------------------------------------------------------------------------------------------
    def Ajouter_Piq_1D(self,A,nom,lien):
        """
        Les valeurs de A sont : (Rp,ep,ad1x,rc,ad2x,)
            Rp  :   rayon du piquage
            ep  :   épaisseur du piquage
            rc   :   rayon de courbure du joint de soudure
            ad1x :   1er angle dihèdre
           ad2x  :   2ème angle dihèdre pour des piquages non perpendiculaire
            
        Nom : nom du piquage
        """
        [Vd,Secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=Vd
        
        [Rp,ep,ad,bd,rc,n] =  ConvNFloat(A,6)

        # INCREMENTATION
        self.nP +=1

        # DEFINITION DES VARIABLES
        [Rc,ec]=self.Secx
        SecPiq=[Rp,ep]
        Piq = "Piq" + str(self.nP)

        # PARTIE PRINCIPALE
        # Création d'un tuyau avant celle du piquage
        # qui est de nature différente
        
        # Définition des valeurs pour la modèle 3D du piquage
        Lc0 = Kpiq_c*Rp
        Lp0 = Kpiq_p*Rc

        # Vecteur permettant de déterminer la position du point Pn sur le collecteur
        Vtn =  VectRatio(self.Vd2x,Lc0)
        Vtns =  VectString2(Vtn)
        
        # Vecteur permettant de déterminer la position du point permettant de trouver la courbe   
        Vd2xe =  VectRatio(self.Vd2x,Lc0-Rp)
        Vd2xes =  VectString2(Vd2xe)
        
        # Vecteur permettant de déterminer la position du point P2 sur le piquage
        Vd3x =  VectDih(Rc,self.Vd1x,self.Vd2x,ad,bd)
        Vd3xs =  VectString2(Vd3x)

        Vd4x = ProdVect(self.Vd2x,Vd3x)
        Vd4x = VectRatio(Vd4x,Rc)
        Vd4s = VectString2(Vd4x)

        Vd4 = VectRatio(Vd4x,(Rc)/1.414)    
        Vd2 = VectRatio(self.Vd2x,-(Rc)/1.414)  
        Vd5x = AddVect([[1,Vd4],[1,Vd2]]) 
        Vd5s = VectString2(Vd5x)
        
        #Position des nouveaux points
        Vd3mp =VectRatio(Vd3x,Lp0)
        VPp =  AddVect([[1,VPx],[1,Vtn],[1,Vd3mp]]) 
        
        Vd3mr =VectRatio(Vd3x,Rc)
        VPr =  AddVect([[1,VPx],[1,Vtn],[1,Vd3mr]]) 
        self.VPx =  AddVect([[1,VPx],[2,Vtn]]) 
        
        Pn = "Pn_"+str(self.nP)
        Pm = "Pm_"+str(self.nP)
        Pr = nom
        Pp = "Pp_"+str(self.nP)

        Vxm = "Vxm_"+str(self.nP)
        Vm1 = "Vm1_"+str(self.nP)
        Vmp = "Vmp_"+str(self.nP)
        Vmr = "Vmp_"+str(self.nP)
        Vrp = "Vrp_"+str(self.nP)
            
        SIFp=2.1    
        self.DicP[Pr] =  [[VectNorm(self.Vd2x),VectNorm(Vd3x)],SecPiq,VPr,Piq,"TUBE","",SIFp,self.Temp,self.Press]  
        self.Ajouter_Liaison(lien)
        self.DicP[Pn] =  [[VectNorm(self.Vd1x),VectNorm(self.Vd2x)],self.Secx,self.VPx,Piq,"TUBE","",self.SIF,self.Temp,self.Press]  

        
        CodeAppend(self.CodeS,[
        #
        "try:",
        "  #Piquage 1D",
        "  print \"Piquage 1D\"",
        "  Liste=[]",
        "  Rp = "+str(Rp),
        "  ep = "+str(ep),
        "  Rc = "+str(Rc),
        "  ec = "+str(ec),
        "  rc = "+str(rc),
        "  Lc0="+str(Lc0),
        "  Lp0="+str(Lp0),
        
        "  Px ="+self.Px,

        "  p2 = geompy.MakeVertexWithRef(Px,"+Vtns+")",
        "  Vd2x = geompy.MakeVector(Px,p2)",
        "  Liste.append([Vd2x,\"Vd2x\"])", 
        
        "  p3 = geompy.MakeVertexWithRef(Px,"+Vd3xs+")",
        "  Vd3x = geompy.MakeVector(Px,p3)",
        "  Liste.append([Vd3x,\"Vd3x\"])", 
        
        "  Pm = geompy.MakeTranslationVectorDistance(Px,Vd2x,Lc0)",
        "  Liste.append([Pm,\"Pm\"])",
        
        "  Pn = geompy.MakeTranslationVectorDistance(Pm,Vd2x,Lc0)",
        "  "+Pn+"=Pn",
        "  Liste.append([Pn,\""+Pn+"\"])", 
        
        "  Pp = geompy.MakeTranslationVectorDistance(Pm,Vd3x,Lp0)",
        "  "+Pp+"=Pp",
        "  Liste.append([Pp,\""+Pp+"\"])", 
        
        "  Pr = geompy.MakeTranslationVectorDistance(Pm,Vd3x,Rc)",
        "  "+Pr+"=Pr",
        "  Liste.append([Pr,\""+Pr+"\"])",  
        
        "  Vxm = geompy.MakeVector(Px,Pm)",
        "  "+Vxm+"=Vxm",
        "  Liste.append([Vxm,\""+Vxm+"\"])",
        
        "  Vm1 = geompy.MakeVector(Pm,Pn)",
        "  "+Vm1+"=Vm1",
        "  Liste.append([Vm1,\""+Vm1+"\"])",    
        
        "  Vmp = geompy.MakeVector(Pm,Pp)",
        "  "+Vmp+"=Vmp",
        "  Liste.append([Vmp,\""+Vmp+"\"])",  
        
        "  Vmr = geompy.MakeVector(Pm,Pr)",
        "  "+Vmr+"=Vmr",
        "  Liste.append([Vmr,\""+Vmr+"\"])", 
            
        "  P5 =  geompy.MakeVertexWithRef(Pm,"+Vd5s+")",
        "  Vd5x = geompy.MakeVector(Pm,P5)",  
        "  Liste.append([Vd5x,\"Vd5x\"])", 

    #BUG : Salome n'accepte pas que j'utilise plusieurs fois la variable C !

        "  C1 = geompy.MakeCircle(Px,Vd2x,Rc)",
        "  Liste.append([C1,\"C1\"])",
        
        "  S1 = geompy.MakeFaceWires([C1], 1)",
        "  Cyl1 = geompy.MakePrismVecH(S1, Vd2x, 2*Lc0)",
        "  Liste.append([Cyl1,\"Cyl1\"])",

        "  C2 = geompy.MakeCircle(Pm,Vd3x,Rp)",
        "  Liste.append([C2,\"C2\"])",
        
        "  S2 = geompy.MakeFaceWires([C2], 1)",
        "  Cyl2 = geompy.MakePrismVecH(S2, Vd3x, Lp0)",
        "  Liste.append([Cyl2,\"Cyl2\"])",

        "  Piq3D= geompy.MakeFuse(Cyl1,Cyl2)",
        "  Liste.append([Piq3D,\"Piq3D\"])",
        #
        "  C3 = geompy.MakeCircle(Px,Vd2x,Rc-ec)",
        "  Liste.append([C3,\"C3\"])",
        
        "  S3 = geompy.MakeFaceWires([C3], 1)",
        "  Liste.append([S3,\"S3\"])",  

        "  Cyl1i = geompy.MakePrismVecH(S3, Vd2x, 2*Lc0)",
        "  Liste.append([Cyl1i,\"Cyl1i\"])",
        #
        "  C4=geompy.MakeCircle(Pm,Vd3x,Rp-ep)",
        "  S4 = geompy.MakeFaceWires([C4], 1)",
        "  Cyl2i = geompy.MakePrismVecH(S4, Vd3x, Lp0)",
        "  Liste.append([Cyl2i,\"Cyl2i\"])",
        #
        "  Piq3Di= geompy.MakeFuse(Cyl1i,Cyl2i)",
        "  Liste.append([Piq3Di,\"Piq3Di\"])",
        
        "  Piq3D=geompy.MakeCut(Piq3D, Piq3Di)",
        "  Liste.append([Piq3D,\"Piq3D\"])",
        #
        "  a = math.asin(Rp/Rc)",
        "  z1 = Rp/math.tan(a)",
        "  p = geompy.MakeTranslationVectorDistance(Pm,Vd3x,(Rc+z1)/2)", 
        "  p = geompy.MakeTranslationVectorDistance(p,Vd5x,Rp)",  
        "  Liste.append([p,\"p\"])",  
         
        "  E = geompy.GetShapesNearPoint(Piq3D,p,geompy.ShapeType[\"EDGE\"],1)", 
        "  Liste.append([E,\"E\"])",   

        "  ide = geompy.GetSubShapeID(Piq3D,E)",
        "  Piq3D = geompy.MakeFillet( Piq3D ,rc, geompy.ShapeType[\"EDGE\"], [ide])",
        "  Piq3D.SetColor(SALOMEDS.Color("+Couleur["TUBE"]+"))",
        "  "+Piq+"3D= Piq3D",
        "  Piq3D_id = geompy.addToStudy(Piq3D,\""+Piq+"3D\")",
        "  gg.createAndDisplayGO(Piq3D_id)",
        "  gg.setDisplayMode(Piq3D_id,1)",
        #
        "  Piq=geompy.MakeCompound(["+Vxm+","+Vm1+","+Vmr+"])",
        "  "+Piq+"=Piq",
        "  Liste.append([Piq,\""+Piq+"\"])", 

        "  for x in Liste:",
        "    geompy.addToStudyInFather(Piq3D,x[0],x[1])",
      
        "  "+Piq+"M= smesh.Mesh("+ Piq +")",   
        "  Regular_TUBE = "+Piq+"M.Segment()",
        "  Nb_Segments = Regular_TUBE.NumberOfSegments( 1 )",
        "  Nb_Segments.SetDistrType( 0 )",
        ])
        
        if self.iQUAD:
            CodeAppend(self.CodeS,[
            "  Quadratic_Mesh = Regular_TUBE.QuadraticMesh()",
            ])
            
        CodeAppend(self.CodeS,[
        "  smesh.SetName("+Piq+"M , '"+ Piq +"M')",
        "  L1=[Pm,Pn,Pp,Pr,Vxm,Vm1,Vmr,Piq]",
        "  for x in L1:",
        "    "+Piq+"M.Group(x)",

        "  "+Piq+"M.Compute()",
        "  conodes = "+Piq+"M.FindCoincidentNodes( 1e-05 )",
        "  "+Piq+"M.MergeNodes(conodes)",

        "except:",
        "  print \"Erreur commande Piq\"",
        "  for x in Liste:",
        "    geompy.addToStudy(x[0],x[1])", 
        "    gg.createAndDisplayGO(O_id)",
        "    gg.setDisplayMode(O_id,1)",
        ])
        
        self.LesLis.append(Vmr)   
        exec("self.Les"+self.model+"s.extend([Vxm,Vm1])")
        self.LesVs_iMat.extend([Vxm,Vm1])
        self.LesRONDs_iSec.extend([Vxm,Vm1]) 
        self.LTout.append(Piq)
        self.Px = Pn   



    #---------------------------------------------------------------------------
    def Ajouter_Pn(self,A,nom,lien) :
        self.DicP[nom] = self.DicP[self.Px]
        CodeAppend(self.CodeS,[
        nom+" ="+self.Px,
        ])
        self.Px=nom
         

    #---------------------------------------------------------------------------
    def Ajouter_Press(self,A,nom,lien) : 
        if A != [] :
            self.Inserer_LesVs_iPress()
            [self.Press]=ConvNFloat(A,1)
            self.iPress = True
            
        elif nom == "FIN":
            self.iPress = False
         
    #---------------------------------------------------------------------------------------------------------------
    def Ajouter_Px(self,A,nom,lien):
        
        self.iDebutTUYAU=True
        [Vdx,secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        self.Px = nom
        [Vdx,Sec,self.VPx,noma,modela,seca,SIFx,self.Temp,self.Press] = self.DicP[self.Px]
        if self.Temp != Tempx : self.Inserer_LesVs_iTemp()
        if self.Press != Pressx : self.Inserer_LesVs_iTemp()
         
         
    #---------------------------------------------------------------------------
    def Ajouter_Pxv(self,A,nom,lien):
        self.iDebutTUYAU=True
        [Vdx,secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        self.Px = nom
        [Vdx,Sec,self.VPx,noma,modela,seca,SIFx,self.Temp,self.Press] = self.DicP[self.Px]
        if self.Temp != Tempx : self.Inserer_LesVs_iTemp()
        if self.Press != Pressx : self.Inserer_LesVs_iTemp()
        [self.Vd1x,self.Vd2x]=Vdx
        Vd2xs = VectString2(self.Vd2x)

        CodeAppend(self.CodeS,[
        "Vd2x = geompy.MakeVectorDXDYDZ("+Vd2xs+")",
        ])
        

    #---------------------------------------------------------------------------
    def Ajouter_Pxvr(self,A,nom,lien):
        self.iDebutTUYAU=True
        [Vdx,secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        # RECUPERATION DES DONNEES
        self.Px = nom
        [Vdx,self.Secx,self.VPx,Vx,modelx,Sec3Dx,SIFx,Temp2,Press2] = self.DicP[self.Px]
        if Temp2 != Tempx : self.Inserer_LesVs_iTemp()
        if Press2 != Pressx : self.Inserer_LesVs_iPress()
        self.Press=Press2
        self.Temp=Temp2
        [self.Vd1x,self.Vd2x]=Vdx
        Vd2xs = VectString2(self.Vd2x)
        [R,e] = self.Secx

        CodeAppend(self.CodeS,[
        "R="+str(R),
        "e="+str(e),
        "Vd2x = geompy.MakeVectorDXDYDZ("+Vd2xs+")",
        ])


    #---------------------------------------------------------------------------
    def Ajouter_Raideur(self,A,nom,lien):
        [self.raideur] = ConvNFloat(A,1)


    #---------------------------------------------------------------------------
    def Ajouter_Repere(self,A,nom,lien):
        self.Repere = nom
        
        
    #---------------------------------------------------------------------------
    def Ajouter_RhoV(self,A,nom,lien):

        if float(A[0]) > 0.001:
            self.iRhoV = True
            # ASTER travaille en tonne!
            self.RhoV = float(A[0])
        else:
            self.iRhoV = False
        
    #---------------------------------------------------------------------------
    def Ajouter_Sc(self,A,nom,lien):
        self.iRed=True
        self.Inserer_LesRONDs_iSec()

        # RECUPERATION DES DONNEES
        [R1,e1]=self.Secx
        [R2,e2,L]=ConvNFloat(A,3)
        self.Secx=[R2,e2]
        Px=self.Px
            
        # INCREMENTATION
        self.nP += 1

        # DEFINITION DES VARIABLES
        Vd2 =  VectRatio(self.Vd2x,L)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd2]])
        Vd2s =  VectString2(Vd2)
        Red = "Red"+str(self.nP)
        Pn = "Pn"+str(self.nP)
        
        K=(3*R1*R1+R2*R2+2*R1*R2)/4/(R1*R1+R2*R2+R1*R2)
        Lg=K*L
        Rg=R1+(R2-R1)*K
        eg=e1+(e2-e1)*K
        SIGPg=self.Press*Rg/2/eg
        
        Vdg =  VectRatio(self.Vd2x,Lg)
        Vdgs =  VectString2(Vdg)
        Pg = "Pg"+str(self.nP)
        Red1 = "RedA"+str(self.nP)
        Red2 = "RedB"+str(self.nP)

        # Infos sur le point nommé
        if nom != "": Pn = nom
        if lien == "s" : SIF=1.8
        
        #Calcul du SIF
        alpha=math.atan(abs(R2-R1)/L)*180/3.14
        SIF=0.5+(alpha/100)*pow(2*R2/e2,0.5)
        if SIF > 2 : SIF=2   
        SIF=max(SIF,self.SIF)
        self.DicP[Px][6]=SIF
        self.DicP[Pn] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,Red,self.model,"",SIF,self.Temp,self.Press]

        # PARTIE PRINCIPALE DE LA PROCEDURE  

        # Création du modèle géométrique
        
        CodeAppend(self.CodeS,[
        "  #",
        "try:",
        "  print(\"Creation de reducteur\")",
        "  Liste=[]",
        "  Px="+Px,
        
        "  Pn = geompy.MakeVertexWithRef(Px," + Vd2s + ")",
        "  "+Pn+"=Pn",
        "  Liste.append([Pn,\"" + Pn + "\"])",
        
        "  Pg = geompy.MakeVertexWithRef(Px," + Vdgs + ")",
        "  "+Pg+"=Pg",
        "  Liste.append([Pg,\"" + Pg + "\"])",
 
        "  Red0 = geompy.MakeVector(Px,Pn)",
        
        "  Red1 = geompy.MakeVector(Px,Pg)",
        "  "+Red1+"=Red1",
        "  Liste.append([Red1,\"" +Red1 + "\"])",
        
        "  Red2 = geompy.MakeVector(Pg,Pn)",
        "  "+Red2+"=Red2",
        "  Liste.append([Red2,\"" +Red2 + "\"])",
        
        "  Red= geompy.MakeCompound([" + Red1 + "," + Red2 + "])",
        "  "+Red+"=Red",
        "  Liste.append([Red,\"" +Red + "\"])",
        
        "  Red3De = geompy.MakeCone(Px,Red0,"+ str(R1) + "," + str(R2)+"," + str(L)+")",
        "  Red3Di = geompy.MakeCone(Px,Red0,"+ str(R1-e1) + "," + str(R2-e2)+"," + str(L)+")",
        "  Red3D = geompy.MakeCut(Red3De,Red3Di)",
        "  Red3D.SetColor(SALOMEDS.Color("+Couleur["TUBE"]+"))",
        "  Red3D_id = geompy.addToStudy(Red3D,\"" + Red+"3D\")",
        "  gg.createAndDisplayGO(Red3D_id)",
        "  gg.setDisplayMode(Red3D_id,1)",
        "  #",
        
    #important :    L' insertion inFather doit être faire avant le maillage
    #               Après ça ne marche pas !

        "  for x in Liste :",
        "     geompy.addToStudyInFather(Red3D,x[0],x[1])",
        "  #",
        "  RedM = smesh.Mesh(Red)",
        "  Regular_TUBE = RedM.Segment()",
        "  Nb_Segments = Regular_TUBE.NumberOfSegments(1)",
        "  Nb_Segments.SetDistrType( 0 )",
        ]) 
        
        if self.iQUAD:
            CodeAppend(self.CodeS,[
            "  Quadratic_Mesh = Regular_TUBE.QuadraticMesh()",
            ])
        
        CodeAppend(self.CodeS,[
        "  smesh.SetName(RedM , '"+Red+"')",
        "  RedM.Compute()",
        "  "+Red+"M =RedM",
        "  RedM.Group("+Red+")",
        "  RedM.Group("+Px +")",
        "  RedM.Group("+Pn +")",
        "  RedM.Group("+Pg +")",
        "  #",
        "  Px = Pn",
        "  R = "+str(R2),
        "  e = "+str(e2),
        "except:",
        "  print \"Erreur Changement de section\"",
        "  for x in Liste :",
        "     geompy.addToStudy(x[0],x[1])",
        "  gg.createAndDisplayGO(O_id)",
        "  gg.setDisplayMode(O_id,0)",
        ])
        
        # Utilisation de Salomé pour définir la force à appliquer 
        # liée au poids du contenur en fonction de l'orientation

        if self.iRhoV:
            if self.iRed_Force_Repartie:
                S1=2*math.pi*(R1-e1/2)*e1
                S2=2*math.pi*(R2-e2/2)*e2
                Fz1 = S1*self.RhoV*self.Vg[2]
                Fz2 = S2*self.RhoV*self.Vg[2]
                # Calcul des forces de pensanteur
                XP1=self.DicP[Px][2]
                XP2=self.VPx
                u=abs(XP2[0]-XP1[0])
                v=abs(XP2[1]-XP1[1])
                w=abs(XP2[2]-XP1[2])
                sord1 = "ORDONNEE=("+str(Fz1)+","+str(Fz2)+"),"
                sord2 = "ORDONNEE=("+str(Fz2)+","+str(Fz1)+"),"
                if u>v and u>w :
                   var="X"
                   if XP2[0]>XP1[0]:
                       x1=XP1[0]
                       x2=XP2[0]
                       sord=sord1
                   else:
                       x1=XP2[0]
                       x2=XP1[0]
                       sord=sord2
                elif v>w:
                   var="Y"
                   if XP2[1]>XP1[1]:
                       x1=XP1[1]
                       x2=XP2[1]
                       sord=sord1
                   else:
                       x1=XP2[1]
                       x2=XP1[1]
                       sord=sord2
                else :
                   var="Z"
                   if XP2[2]>XP1[2]:
                       x1=XP1[2]
                       x2=XP2[2]
                       sord=sord1
                   else:
                       x1=XP2[2]
                       x2=XP1[2]
                       sord=sord2
                #
                # Insertion de la force dans CodeA
                xFr =  TrouverLigne(self.CodeA,"#DEF_FORCE_REDUCTEUR")
                CodeInsert(self.CodeA,xFr,[
                "Fz"+Red+"=DEFI_FONCTION(",
                "     NOM_PARA='"+var+"',",
                "     ABSCISSE=("+str(x1)+","+str(x2)+"),",
                Ind1+sord,
                "     INTERPOL='LIN',",
                "     PROL_DROITE='EXCLU',",
                "     PROL_GAUCHE='EXCLU',",
                ");"
                ])
                #",
                # Affection d'un modèle dans CodeA'",
                xFr =  TrouverLigne(self.CodeA,"#FORCE_F_CONTENU")
                CodeInsertI(self.CodeA,xFr,2,[
                "_F(",
                "   GROUP_MA='"+Red+"',",
                "   FZ=Fz"+Red+",",
                "),",
                ])
                
            else:
                self.LesMasses.append(Pg)
                Ri1=R1-e1
                Ri2=R2-e2
                masse=math.pi*L*(Ri1*Ri1+Ri2*Ri2+Ri1*Ri2)/3*self.RhoV*1E-9
                Lx =  TrouverLigne(self.CodeA,"#MASSE_DISCRET")
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   GROUP_MA='"+Pg+"A',",
                "   CARA='M_T_D_N',",
                "   VALE=("+str(masse)+"),",
                "),",
#                "_F(",
#                "   GROUP_MA='"+Pg+"A',",
#                "   CARA='K_T_D_N',",
#                "   VALE=(0,0,0),",
#                "   REPERE='LOCAL',",
#                "),",
                ])

        
        # Insertion dans TUBA.comm",
        
        # Déclaration des éléments dans AFFE_MODEL",Pipe +"

        exec("self.Les"+self.model+"s.append(Red)")
       
        Lx =  TrouverLigne(self.CodeA,"#SECTION_POUTRE")
        CodeInsertI(self.CodeA,Lx,2,[
        "_F(",
        "   GROUP_MA='"+Red +"',",
        "   SECTION ='CERCLE',",
        "   VARI_SECT ='HOMOTHETIQUE',",
        "   CARA = ('R1','R2','EP1','EP2',),",
        "   VALE = ("+str(R1)+","+str(R2)+","+str(e1)+","+str(e2)+"),",
        "),",
        ])
        
        self.LesVs_iMat.append(Red)
        if self.iTemp: self.LesVs_iTemp.append(Red)
        
        if self.iCalc_Flex:
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=('"+Pg+"A'),",
            "   NOM_CMP='TEMP',",
            "   VALE="+str(SIGPg)+",",         
            "   ),",
            ]
            
            Lx =  TrouverLigne(self.CodeA,"#CHAMP_SIGP")
            CodeInsertI(self.CodeA,Lx,2,LTex) 
        
        # ENREGISTREMENTS POUR LA SUITE
        self.LTout.append(Red)
        self.Px = Pn
        self.Ajouter_Liaison(lien)

  
    #---------------------------------------------------------------------------
    def Ajouter_Section(self,A,nom,lien): 
        self.Inserer_LesRONDs_iSec()
        self.Inserer_LesRECTs_iSec()
        self.Inserer_LesPOUTREs_iSec()
        self.Secx=nom  
        
        
    #---------------------------------------------------------------------------
    def Ajouter_Seisme(self):         
        if self.Calcul in ["ANALYSE_SISMIQUE"]:
            if self.Supportx in ["CB","PF"]:
                LTex=[     
                "_F(     GROUP_NO = '"+self.Px+"',",
                "       AXE = ( 1., 1., 0., ),",
                "       SPEC_OSCI = SPECT_XY,",
                "       ECHELLE = 1.",
                "       ),",
                "_F(     GROUP_NO = '"+self.Px+"',",
                "       AXE = ( 0., 0., 1., ),",
                "       SPEC_OSCI = SPECT_Z,",
                "       ECHELLE = 1.",
                "       ),"  
                ] 
                 
                LTex2=[ 
                "_F(     GROUP_NO = '"+self.Px+"',",
                "        AVEC_CMP = ('DX','DY','DZ',),",
                "       ),",
                ]
        
            elif self.Supportx in ["GL"]:
                vd2x=VectNorm(self.Vd2x)
                cx=1-ProdScal(vd2x,[1,0,0])
                cy=1-ProdScal(vd2x,[0,1,0])
                cz=1-ProdScal(vd2x,[0,0,1])
                LTex=[     
                "_F(     GROUP_NO = '"+self.Px+"',",
                "       AXE = ( "+str(cx)+","+str(cy)+", 0., ),",
                "       SPEC_OSCI = SPECT_XY,",
                "       ECHELLE = 1.",
                "       ),",
                "_F(     GROUP_NO = '"+self.Px+"',",
                "       AXE = ( 0., 0., "+str(cz)+", ),",
                "       SPEC_OSCI = SPECT_Z,",
                "       ECHELLE = 1.",
                "       ),",
                ]
                
                tex=""
                rmin=0.1
                if cx>rmin :tex+="'DX',"
                if cy>rmin :tex+="'DY',"
                if cz>rmin :tex+="'DZ',"
                
                LTex2=[ 
                "_F(     GROUP_NO = '"+self.Px+"',",
                "        AVEC_CMP = ("+tex+")",
                "       ),",
                ]
                
            Lx=TrouverLigne(self.CodeA,"#SPECTRE_NOEUD")
            CodeInsertI(self.CodeA,Lx,4,LTex)
            
            Lx=TrouverLigne(self.CodeA,"#DIR_PSEUDO_MODE")
            CodeInsertI(self.CodeA,Lx,4,LTex2) 
        
     
    #---------------------------------------------------------------------------
    def Ajouter_Sce(self,A,nom,lien):
        self.iRed=True
        self.Inserer_LesRONDs_iSec()

        # RECUPERATION DES DONNEES
        [R1,e1]=self.Secx
        [R2,e2,L,ad]=ConvNFloat(A,4)
        self.Secx=[R2,e2]
        Px=self.Px
        
        Ve =  VectDih(abs(R2-R1),self.Vd1x,self.Vd2x,ad,0)
        Ves = VectString2(Ve)
            
        # INCREMENTATION
        self.nP += 1

        # DEFINITION DES VARIABLES
        Vd2 =  VectRatio(self.Vd2x,L)
        Vd2e =  AddVect([[1,Vd2],[1,Ve]])
        self.VPx =  AddVect([[1,self.VPx],[1,Vd2e]])
        Vd2es =  VectString2(Vd2e)
        Red = "Red"+str(self.nP)
        Pn = "Pn"+str(self.nP)
        self
        
        K=(3*R1*R1+R2*R2+2*R1*R2)/4/(R1*R1+R2*R2+R1*R2)
        Lg=K*L
        Rg=R1+(R2-R1)*K
        eg=e1+(e2-e1)*K
        SIGPg=self.Press*Rg/2/eg
        
        Vdg =  VectRatio(Vd2e,Lg)
        Vdgs =  VectString2(Vdg)
        Pg = "Pg"+str(self.nP)
        Red1 = "RedA"+str(self.nP)
        Red2 = "RedB"+str(self.nP)

        # Infos sur le point nommé
        if nom != "": Pn = nom
        if lien == "s" : SIF=1.8
        alpha=math.atan(abs(2*(R2-R1))/L)*180/3.14
        SIF=0.5+(alpha/100)*pow(2*R2/e2,0.5)
        if SIF > 2 : SIF=2   
        SIF=max(SIF,self.SIF)
        self.DicP[Px][6]=SIF
        self.DicP[Pn] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,Red,self.model,"",SIF,self.Temp,self.Press]

        # PARTIE PRINCIPALE DE LA PROCEDURE  

        # Création du modèle géométrique
        
        CodeAppend(self.CodeS,[
        "  #",
        "try:",
        "  print(\"Creation de "+Red+"\")",
        "  R="+str(R2),
        "  e="+str(e2),
        "  R1="+str(R1),
        "  e1="+str(e1),
        "  Liste=[]",
        "  Px="+Px,
        
        "  Pn = geompy.MakeVertexWithRef(Px," + Vd2es + ")",
        "  "+Pn+"=Pn",
        "  Liste.append([Pn,\"" + Pn + "\"])",
        
        "  Pg = geompy.MakeVertexWithRef(Px," + Vdgs + ")",
        "  "+Pg+"=Pg",
        "  Liste.append([Pg,\"" + Pg + "\"])",
 
        "  Red0 = geompy.MakeVector(Px,Pn)",
        
        "  Red1 = geompy.MakeVector(Px,Pg)",
        "  "+Red1+"=Red1",
        "  Liste.append([Red1,\"" +Red1 + "\"])",
        
        "  Red2 = geompy.MakeVector(Pg,Pn)",
        "  "+Red2+"=Red2",
        "  Liste.append([Red2,\"" +Red2 + "\"])",
        
        "  Red= geompy.MakeCompound([" + Red1 + "," + Red2 + "])",
        "  "+Red+"=Red",
        "  Liste.append([Red,\"" +Red + "\"])",
        
        "  S1ext = geompy.MakeCircle(Px,Vd2x,R1)",
        "  Liste.append([S1ext,\"S1ext\"])",
        "  S2ext = geompy.MakeCircle("+Pn+",Vd2x,R)",
        "  Liste.append([S2ext,\"S2ext\"])",
        "  Red3DExt = geompy.MakeThruSections([S1ext,S2ext], theModeSolid=1, thePreci = 0.001, theRuled=1)",
        
        "  S1int = geompy.MakeCircle(Px,Vd2x,R1-e1)",
        "  Liste.append([S1int,\"S1int\"])",
        "  S2int = geompy.MakeCircle("+Pn+",Vd2x,R-e)",
        "  Liste.append([S2int,\"S2int\"])",
        "  Red3DInt = geompy.MakeThruSections([S1int,S2int], theModeSolid=1, thePreci = 0.001, theRuled=1)",
        
        "  Red3D = geompy.MakeCut(Red3DExt,Red3DInt)",
        "  Red3D.SetColor(SALOMEDS.Color("+Couleur[self.model]+"))",
        "  Red3D_id = geompy.addToStudy(Red3D,\"" + Red+"3D\")",
        "  gg.createAndDisplayGO(Red3D_id)",
        "  gg.setDisplayMode(Red3D_id,1)",
        "  #",
        "  for x in Liste :",
        "     geompy.addToStudyInFather(Red3D,x[0],x[1])",
        "  #",
        "except:",
        "  print \"   ERREUR geometrie !\"",
        "  for x in Liste :",
        "     geompy.addToStudy(x[0],x[1])",
        "  gg.createAndDisplayGO(O_id)",
        "  gg.setDisplayMode(O_id,0)",
        ])
        
    #important :    L' insertion inFather doit être faire avant le maillage
    #               Après ça ne marche pas !

        
        CodeAppend(self.CodeS,[
        "try:",
        "  RedM = smesh.Mesh(Red)",
        "  Regular_TUBE = RedM.Segment()",
        "  Nb_Segments = Regular_TUBE.NumberOfSegments(1)",
        "  Nb_Segments.SetDistrType( 0 )",
        ]) 
        
        if self.iQUAD:
            CodeAppend(self.CodeS,[
            "  Quadratic_Mesh = Regular_TUBE.QuadraticMesh()",
            ])
        
        CodeAppend(self.CodeS,[
        "  smesh.SetName(RedM , '"+Red+"')",
        "  RedM.Compute()",
        "  "+Red+"M =RedM",
        "  RedM.Group("+Red+")",
        "  RedM.Group("+Px +")",
        "  RedM.Group("+Pn +")",
        "  RedM.Group("+Pg +")",
        "  #",
        "except:",
        "  print \"   ERREUR maillage !\"",
        ])
        
        # Utilisation de Salomé pour définir la force à appliquer 
        # liée au poids du contenur en fonction de l'orientation

        if self.iRhoV:
            if self.iRed_Force_Repartie:
                S1=2*math.pi*(R1-e1/2)*e1
                S2=2*math.pi*(R2-e2/2)*e2
                Fz1 = S1*self.RhoV*self.Vg[2]
                Fz2 = S2*self.RhoV*self.Vg[2]
                # Calcul des forces de pensanteur
                XP1=self.DicP[Px][2]
                XP2=self.VPx
                u=abs(XP2[0]-XP1[0])
                v=abs(XP2[1]-XP1[1])
                w=abs(XP2[2]-XP1[2])
                sord1 = "ORDONNEE=("+str(Fz1)+","+str(Fz2)+"),"
                sord2 = "ORDONNEE=("+str(Fz2)+","+str(Fz1)+"),"
                if u>v and u>w :
                   var="X"
                   if XP2[0]>XP1[0]:
                       x1=XP1[0]
                       x2=XP2[0]
                       sord=sord1
                   else:
                       x1=XP2[0]
                       x2=XP1[0]
                       sord=sord2
                elif v>w:
                   var="Y"
                   if XP2[1]>XP1[1]:
                       x1=XP1[1]
                       x2=XP2[1]
                       sord=sord1
                   else:
                       x1=XP2[1]
                       x2=XP1[1]
                       sord=sord2
                else :
                   var="Z"
                   if XP2[2]>XP1[2]:
                       x1=XP1[2]
                       x2=XP2[2]
                       sord=sord1
                   else:
                       x1=XP2[2]
                       x2=XP1[2]
                       sord=sord2
                #
                # Insertion de la force dans CodeA
                xFr =  TrouverLigne(self.CodeA,"#DEF_FORCE_REDUCTEUR")
                CodeInsert(self.CodeA,xFr,[
                "Fz"+Red+"=DEFI_FONCTION(",
                "     NOM_PARA='"+var+"',",
                "     ABSCISSE=("+str(x1)+","+str(x2)+"),",
                Ind1+sord,
                "     INTERPOL='LIN',",
                "     PROL_DROITE='EXCLU',",
                "     PROL_GAUCHE='EXCLU',",
                ");"
                ])
                #",
                # Affection d'un modèle dans CodeA'",
                xFr =  TrouverLigne(self.CodeA,"#FORCE_F_CONTENU")
                CodeInsertI(self.CodeA,xFr,2,[
                "_F(",
                "   GROUP_MA='"+Red+"',",
                "   FZ=Fz"+Red+",",
                "),",
                ])
                
            else:
                self.LesMasses.append(Pg)
                Ri1=R1-e1
                Ri2=R2-e2
                masse=math.pi*L*(Ri1*Ri1+Ri2*Ri2+Ri1*Ri2)/3*self.RhoV*1E-9
                Lx =  TrouverLigne(self.CodeA,"#MASSE_DISCRET")
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   GROUP_MA='"+Pg+"A',",
                "   CARA='M_T_D_N',",
                "   VALE=("+str(masse)+"),",
                "),",
#                "_F(",
#                "   GROUP_MA='"+Pg+"A',",
#                "   CARA='K_T_D_N',",
#                "   VALE=(0,0,0),",
#                "   REPERE='LOCAL',",
#                "),",
                ])

        
        # Insertion dans TUBA.comm",
        
        # Déclaration des éléments dans AFFE_MODEL",Pipe +"

        exec("self.Les"+self.model+"s.append(Red)")
       
        Lx =  TrouverLigne(self.CodeA,"#SECTION_POUTRE")
        CodeInsertI(self.CodeA,Lx,2,[
        "_F(",
        "   GROUP_MA='"+Red +"',",
        "   SECTION ='CERCLE',",
        "   VARI_SECT ='HOMOTHETIQUE',",
        "   CARA = ('R1','R2','EP1','EP2',),",
        "   VALE = ("+str(R1)+","+str(R2)+","+str(e1)+","+str(e2)+"),",
        "),",
        ])
        
        self.LesVs_iMat.append(Red)
        if self.iTemp: self.LesVs_iTemp.append(Red)
        
        
        if self.iCalc_Flex:
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=('"+Pg+"A'),",
            "   NOM_CMP='TEMP',",
            "   VALE="+str(SIGPg)+",",         
            "   ),",
            ]
            
            Lx =  TrouverLigne(self.CodeA,"#CHAMP_SIGP")
            CodeInsertI(self.CodeA,Lx,2,LTex) 
        
        # ENREGISTREMENTS POUR LA SUITE
        self.LTout.append(Red)
        self.Px = Pn
        self.Ajouter_Liaison(lien)
     
          
     
     
    #---------------------------------------------------------------------------------------------------------------
    def Ajouter_Si(self,A,nom,lien):
    
        # Remarque : Pas besoin de faire de If car seule une liste contient
        # quelque chose. L'appel de toutes les fonctions concernées suffit.
        self.Inserer_LesRONDs_iSec()
        self.Inserer_LesRECTs_iSec()
        self.Inserer_LesPOUTREs_iSec()
    
        if self.model in LesModeles_ROND:  
        
            [R,e]=  ConvNFloat(A,2)
            if e==0: e=R
            self.Secx=[R,e]
            
            CodeAppend(self.CodeS,[
            "R="+str(R),
            "e="+str(e)
            ])
            
        elif self.model in ["POUTRE_RECTANGLE"]:

            [Hy,Hz,ey,ez]=  ConvNFloat(A,4)
            if ez==0:ez=ey
            self.Secx=[Hy,Hz,ey,ez,self.angleP]
           
                
            
     


    #---------------------------------------------------------------------------------------------------------------
    def Ajouter_Soudure(self):
        try :
                [Vdx,Secx,VPx,Vx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        except(KeyError):
                Secx = self.Secx

        Sd="Sd"+str(self.nP)
        Vd2xs=VectString2(self.Vd2x)
        CodeAppend(self.CodeS,[
        "#Ajout de la soudure",
        "R="+str(Secx[0]),
        "e="+str(Secx[1]),
        "V=geompy.MakeVectorDXDYDZ("+Vd2xs+")",
        "Ce=geompy.MakeCircle("+self.Px+",V,R*1.05)",
        "Ci=geompy.MakeCircle("+self.Px+",V,R-e)",
        "F=geompy.MakeFaceWires([Ce,Ci],1)",
        ""+Sd + "=geompy.MakePrismVecH2Ways(F, V, R*0.2)",
        ""+Sd + ".SetColor(SALOMEDS.Color(0,0.333333,0))",
        ""+Sd + "_id=geompy.addToStudy("+ Sd +",\""+ Sd +"\")",
        "gg.createAndDisplayGO("+ Sd +"_id)",
        "gg.setDisplayMode("+ Sd +"_id,1)",
        ])
    

    #---------------------------------------------------------------------------
    def Ajouter_Support(self,Typ,A,nom,repere):
    
        [Vdx,Secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[nom]        
        [Vd1x,Vd2x]=Vdx 
        self.Vd1x=Vd1x
        self.Vd2x=Vd2x
        couleur = Couleur["Support"][Typ]
        
        Sup = Typ +"_" + nom 
        
        if modelx in LesModeles_ROND:
            [R,e] = Secx
            Re = 1.25*R 
            
            if A==[]:
                Lc=R
            else:
                [Lc]=ConvNFloat(A,1)
                  
              
            CodeAppend(self.CodeS,[
            "try:",
            "  Liste=[]",
            "  Lc = "+str(Lc),
            "  Px = "+nom,
            "  Re="+str(Re),
            "  R="+str(R),
            
            "  Vd2x = geompy.MakeVectorDXDYDZ("+VectString2(self.Vd2x)+")",
            "  Liste.append([Vd2x,\"Vd2x\"])",
            
            "  CercleExt=geompy.MakeCircle( Px,Vd2x,R*1.2)",
            "  Liste.append([CercleExt,\"CercleExt\"])",
            
            "  CercleInt=geompy.MakeCircle( Px,Vd2x,R)",
            "  Liste.append([CercleInt,\"CercleInt\"])",
            
            "  S = geompy.MakeFaceWires([CercleExt, CercleInt], 1)",
            "  Liste.append([S,\"S\"])", 
            
            "  Sup=geompy.MakePrismVecH2Ways(S, Vd2x,Lc)",
            "  Sup_id=geompy.addToStudy(Sup,\""+Sup+"a\")",

            "  Sup.SetColor(SALOMEDS.Color("+couleur[0]+"))",
            "  gg.createAndDisplayGO(Sup_id)",
            "  gg.setDisplayMode(Sup_id,1)",

            
            "  CercleExt=geompy.MakeCircle( Px,Vd2x,R*1.3)",
            "  Liste.append([CercleExt,\"CercleExt\"])",
            
            "  CercleInt=geompy.MakeCircle( Px,Vd2x,R*1.1)",
            "  Liste.append([CercleInt,\"CercleInt\"])",
            
            "  S = geompy.MakeFaceWires([CercleExt, CercleInt], 1)",
            "  Liste.append([S,\"S\"])", 
             
            "  Sup2 = geompy.MakePrismVecH2Ways(S, Vd2x,Lc/3)",
            "  Sup2_id=geompy.addToStudyInFather(Sup,Sup2,\""+Sup+"b\")",
            "  Sup2.SetColor(SALOMEDS.Color("+couleur[1]+"))",   

            "  gg.createAndDisplayGO(Sup2_id)",
            "  gg.setDisplayMode(Sup2_id,1)",

            "  for x in Liste :",
            "    geompy.addToStudyInFather(Sup,x[0],x[1])",
             
            "except:",
            "  print ",
            "  print \""+Sup+":Erreur\"",
            "  for x in Liste :",
            "    geompy.addToStudy(x[0],x[1])",
            "  gg.createAndDisplayGO(O_id)",
            "  gg.setDisplayMode(O_id,1)",
            ])
            
        elif modelx == "POUTRE_RECTANGLE":
        
            [Hy,Hz,ey,ez,angleP]=Secx
            
            if A==[]:
                Lc=(Hy+Hz)/2
            else:
                [Lc]=ConvNFloat(A,1)
            
            L1=Hy/2
            L2=Hz/2
            L2s=str(L2)
            L1s=str(L1)
            Le2s=str(L2*1.2)
            Le1s=str(L1*1.2)
            La2s=str(L2*1.3)
            La1s=str(L1*1.3)
            vi3=VectNorm(Vd2x)
            vi3s=VectString2(vi3)
            
            if VerifierColinea(vi3,[0,0,1]) == 0 :
                vj3=ProdVect([0,0,1],vi3)
                vk3=ProdVect(vi3,vj3)
                vj3r=RotVect(vj3,vi3,self.angleP)
                vk3r=RotVect(vk3,vi3,self.angleP)
                
            else:
                vj3r=RotVect([1,0,0],[0,0,1],self.angleP)
                vk3r=RotVect([0,1,0],[0,0,1],self.angleP)
                    
            vj3rs=VectString2(vj3r)
            vk3rs=VectString2(vk3r)
            VPxs = VectString2(VPx)
            
            CodeAppend(self.CodeS,[
            "try:",
            "   Liste=[]",
            "   Lc = "+str(Lc),
            "   Vd2x = geompy.MakeVectorDXDYDZ("+VectString2(self.Vd2x)+")",
            "   W1 = geompy.MakeSketcher(\"Sketcher: F "+L1s+" "+L2s+": TT -"+L1s+" "+L2s+": TT -"+L1s+" -"+L2s+": TT "+L1s+" -"+L2s+": WW\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            
            "   W2 = geompy.MakeSketcher(\"Sketcher: F "+Le1s+" "+Le2s+": TT -"+Le1s+" "+Le2s+": TT -"+Le1s+" -"+Le2s+": TT "+Le1s+" -"+Le2s+": WW\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   S = geompy.MakeFaceWires([W1, W2], 1)",
            "   Liste.append([S ,\"S\"])",
            "   Sup=geompy.MakePrismVecH2Ways(S, Vd2x,Lc)",
            "   Sup_id=geompy.addToStudy(Sup,\""+Sup+"a\")",

            "   Sup.SetColor(SALOMEDS.Color("+couleur[0]+"))",
            "   gg.createAndDisplayGO(Sup_id)",
            "   gg.setDisplayMode(Sup_id,1)",
            
            "   W3 = geompy.MakeSketcher(\"Sketcher: F "+La1s+" "+La2s+": TT -"+La1s+" "+La2s+": TT -"+La1s+" -"+La2s+": TT "+La1s+" -"+La2s+": WW\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   S = geompy.MakeFaceWires([W2, W3], 1)",
            "   Liste.append([S ,\"S\"])",
            "   Sup=geompy.MakePrismVecH2Ways(S, Vd2x,Lc/3)",
            "   Sup_id=geompy.addToStudy(Sup,\""+Sup+"b\")",

            "   Sup.SetColor(SALOMEDS.Color("+couleur[1]+"))",
            "   gg.createAndDisplayGO(Sup_id)",
            "   gg.setDisplayMode(Sup_id,1)",
            
            "   for x in Liste :",
            "       geompy.addToStudyInFather(Pipe,x[0],x[1])",

            "except:",
            "   ERREUR=True",
            "   print (\"   =>ERREUR!\")",
            "   for x in Liste :",
            "       geompy.addToStudy(x[0],x[1])",
            ])
        

        elif modelx in ["POUTRE"]:
        
            Lc=min(LesSections[Secx][0])
            vi3=VectNorm(Vd2x)
            vi3s=VectString2(vi3)
            
            if VerifierColinea(vi3,[0,0,1]) == 0 :
                vj3=ProdVect([0,0,1],vi3)
                vk3=ProdVect(vi3,vj3)
                vj3r=RotVect(vj3,vi3,self.angleP)
                vk3r=RotVect(vk3,vi3,self.angleP)
                
            else:
                vj3r=RotVect([1,0,0],[0,0,1],self.angleP)
                vk3r=RotVect([0,1,0],[0,0,1],self.angleP)
                    
            vj3rs=VectString2(vj3r)
            vk3rs=VectString2(vk3r)
            VPxs = VectString2(VPx)
            
            CodeAppend(self.CodeS,[
            "try:",
            "   print(\"Support en "+nom+"\")",
            "   Liste=[]",
            "   Lc = "+str(Lc),
            "   Vd2x = geompy.MakeVectorDXDYDZ("+VectString2(self.Vd2x)+")",
            "   W3 = geompy.MakeSketcher(\"Sketcher:"+LesSections[Secx][3]+"\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   S3 = geompy.MakeFaceWires([W3], 1)",
            "   Liste.append([S3 ,\"S3\"])",
            "   Sup3=geompy.MakePrismVecH2Ways(S3, Vd2x,Lc)",
            "   Sup3_id=geompy.addToStudy(Sup3,\""+Sup+"a\")",
            "   Sup3.SetColor(SALOMEDS.Color("+couleur[0]+"))",
            "   gg.createAndDisplayGO(Sup3_id)",
            "   gg.setDisplayMode(Sup3_id,1)",
            
            "   W4 = geompy.MakeSketcher(\"Sketcher:"+LesSections[Secx][4]+"\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   S4 = geompy.MakeFaceWires([W4], 1)",
            "   Liste.append([S4 ,\"S4\"])",
            "   Sup4=geompy.MakePrismVecH2Ways(S4, Vd2x,Lc/3)",
            "   Sup4.SetColor(SALOMEDS.Color("+couleur[1]+"))",
            "   Sup4_id=geompy.addToStudyInFather(Sup3,Sup4,\""+Sup+"a\")",
            "   gg.createAndDisplayGO(Sup4_id)",
            "   gg.setDisplayMode(Sup4_id,1)",

            "   for x in Liste :",
            "       geompy.addToStudyInFather(Sup3,x[0],x[1])",

            "except:",
            "   ERREUR=True",
            "   print (\"   =>ERREUR!\")",
            "   for x in Liste :",
            "       geompy.addToStudy(x[0],x[1])",
            ])


        if Typ == "PF":
            if modelx in ["TUBE","POUTRE_RECTANGLE","POUTRE"]:
                Vi=[
                    0,0,0,
                    0,0,0,
                    ]
            elif modelx in ["BARRE","CABLE","RESSORT"]: 
                Vi=[
                    0,0,0,
                    x,x,x,
                    ]
            elif modelx in ["TUYAU3M"]:
                Vi=[
                    0,0,0,
                    0,0,0,
                    ]
            elif modelx in ["TUYAU6M"]:
                Vi=[
                    0,0,0,
                    0,0,0,
                    ]
                    
        elif Typ == "CB" :
                Vi=[
                    0,0,0,
                    x,x,x,
                    ]
        elif Typ == "GL" : 
                Vi=[
                    x,0,0,
                    0,0,0,
                    ]
         
        self.Ajouter_Liaison_Oblique(nom,Vi,repere) 
         
        nA = len(A)    
        if nA > 1:
                KTX=A[1]
                KTY=A[2]
                KTZ=A[3]
                KRX=A[4]
                KRY=A[5]
                KRZ=A[6]
                xR=Trouverligne(self.CodeA,"RESSORT")
                CodeInsertI(self.CodeA,xR,1,[
                "_F(",
                "GROUP_MA = '" + nom + "',",
                "REPERE = '"+repere+"',",
                "CARA = 'K_TR_D_N',",
                "VALE = (",
                "         " + KX + ",",
                "         " + KY + ",",
                "         " + KZ + ",",
                "         " + KRX + ",",
                "         " + KRY + "," ,
                "         " + KRZ + ",),",
                "),",
                ])
        
    #---------------------------------------------------------------------------
    def Ajouter_Liaison_Oblique(self,nom,ddl,Repere)  :
        if Repere == "LOCAL" :
            vd2x = VectNorm(self.Vd2x)
            [x2,y2,z2]=vd2x
            vd1x = VectNorm(self.Vd1x)
            [x1,y1,z1]=vd1x
            
            vd3x=ProdVect(vd2x,vd1x)
            vd4x=ProdVect(vd2x,vd3x)
            [x4,y4,z4]=vd4x
            
            # Rotation / Z
            if abs(x2)<eps:
                if y2 > 0 :
                    alpha = 90
                else:
                    alpha = -90
            else:
                alpha = math.atan(abs(y2/x2))*180/math.pi
                if x2<0 : alpha =180-alpha
                if y2<0 : alpha =360-alpha
            
            
            # Rotation / Y1
            H=pow(pow(x2,2)+pow(y2,2),0.5)
            if H < eps :
                if z2 > 0:
                    beta = 90
                else:
                    beta = -90
            else:        
                beta=math.atan(z2/H)*180/math.pi
            
            
            # Rotation / X2
            # la prise en compte de cette inclinaison n'a pas d'importance
            
            gamma= 0    
        
        elif Repere == "GLOBAL":
        
            alpha = 0
            beta = 0
            gamma = 0
        
        Lx =  TrouverLigne(self.CodeA,"#LIAISON_OBLIQUE")
        for i,x in enumerate(ddl):
            if str(x) != "x":
                tex = DDL[i]+"="+str(x)
                self.nDDL +=1
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(    GROUP_NO='" + nom + "',",
                "       "+tex+",",
                "       ANGL_NAUT=("+str(alpha)+","+str(beta)+","+str(gamma)+"),",
                "),",                               
                ])


    #---------------------------------------------------------------------------
    def Ajouter_Temp(self,A,nom,lien):
        
        if A != [] :
            self.Inserer_LesVs_iTemp()
            [self.Temp]=ConvNFloat(A,1)
            self.iTemp = True
            
        elif nom == "FIN":
            self.iTemp = False



    #----------------------------------------------------------------------    
    def Ajouter_VPiq(self,A,nom,lien):
        """
        Les valeurs de A sont : (Rp,ep,ad1x,ad2x,rc)
            Rp  :   rayon du piquage
            ep  :   épaisseur du piquage
            ad1x :   1er angle dihèdre
            ad2x  :   2ème angle dihèdre pour des piquages non perpendiculaire
            rc   :   rayon de courbure du joint de soudure
            
        Nom : nom du piquage
        """
        [Vd,Secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=Vd
        # RECUPERATION DES INFORMATIONS
        [Rp,ep,ad,bd,rc] =  ConvNFloat(A,5)

        # INCREMENTATION
        self.nP +=1

        # DEFINITION DES VARIABLES
        [Rc,ec]=self.Secx
        SecPiq=[Rp,ep]
        VPiq = "VPiq" + str(self.nP)

        # PARTIE PRINCIPALE
        # Création d'un tuyau avant celle du piquage
        # qui est de nature différente
        
        # Définition des valeurs pour la modèle 3D du piquage
        Lp0 = KVpiq_p*Rc

        Vd3x =  VectDih(Rc,self.Vd1x,self.Vd2x,ad,bd)
        Vd3xs =  VectString2(Vd3x)

        VPr =  AddVect([[1,self.VPx],[1,Vd3x]]) 

        Pp = "Pp_"+str(self.nP)
        Pr = "Pr_"+str(self.nP)
        Vxr = "Vxr_"+str(self.nP)
        Vrp = "Vrp_"+str(self.nP)
        if nom!="": Pr=nom
        
        # Calcul du SIF
        h=ec/(Rc-ec/2)
        SIF=0.9*pow(h,-2/3)  
        self.DicP[Pr] =  [[VectNorm(self.Vd2x),VectNorm(Vd3x)],SecPiq,VPr,VPiq,"TUBE","",SIF,self.Temp,self.Press]  
        
       
        CodeAppend(self.CodeS,[
        #
        "try:",
        "  #Piquage 1D",
        "  print \"Piquage 1D\"",
        "  Liste=[]",
        "  Rp = "+str(Rp),
        "  ep = "+str(ep),
        "  Rc = "+str(Rc),
        "  ec = "+str(ec),
        "  Lp0="+str(Lp0),
        
        "  Px ="+self.Px,
        
        "  Pr = geompy.MakeVertexWithRef(Px,"+Vd3xs+")",
        "  "+Pr+"=Pr",
        "  Liste.append([Pr,\""+Pr+"\"])",  
        
        "  Vd3x = geompy.MakeVector(Px,Pr)",

        "  Pp = geompy.MakeTranslationVectorDistance(Px,Vd3x,Lp0)",
        "  "+Pp+"=Pp",
        "  Liste.append([Pp,\""+Pp+"\"])", 

        "  Vxr = geompy.MakeVector(Px,Pr)",
        "  "+Vxr+"=Vxr",
        "  Liste.append([Vxr,\""+Vxr+"\"])", 
        
        "  Vrp = geompy.MakeVector(Pr,Pp)",
        "  "+Vrp+"=Vrp",
        "  Liste.append([Vrp,\""+Vrp+"\"])",  
        
        "  VPiq=geompy.MakeCompound(["+Vxr+","+Vrp+"])",
        "  "+VPiq+"=VPiq",
        "  Liste.append([VPiq,\""+VPiq+"\"])", 


    #BUG : Salome n'accepte pas que j'utilise plusieurs fois la variable C !

        "  Cpe = geompy.MakeCircle(Px,Vd3x,Rp*0.95)",
        "  Liste.append([Cpe,\"Cpe\"])",
        
        "  Spe = geompy.MakeFaceWires([Cpe], 1)",
        "  Cylpe = geompy.MakePrismVecH(Spe, Vd3x, Lp0)",
        "  Liste.append([Cylpe,\"Cylpe\"])",
        
        "  Cpi = geompy.MakeCircle(Px,Vd3x,Rp-ep)",
        "  Liste.append([Cpi,\"Cpi\"])",
        
        "  Spi = geompy.MakeFaceWires([Cpe,Cpi], 1)",
        "  Cylpi = geompy.MakePrismVecH(Spi, Vd3x, Lp0)",
        "  Liste.append([Cylpi,\"Cylpi\"])",

        "  VPiq3D=geompy.MakeCut(Cylpe, Cylpi)",
        "  Liste.append([VPiq3D,\"VPiq3D\"])",

        "  VPiq3D.SetColor(SALOMEDS.Color("+Couleur["Piq"]+"))",
        "  "+VPiq+"3D= VPiq3D",
        "  VPiq3D_id = geompy.addToStudy(VPiq3D,\""+VPiq+"3D\")",
        "  gg.createAndDisplayGO(VPiq3D_id)",
        "  gg.setDisplayMode(VPiq3D_id,1)",
        
        "  for x in Liste:",
        "    geompy.addToStudyInFather(VPiq3D,x[0],x[1])",
      
        "except:",
        "  print \"Erreur VPiq : geometrie\"",
        "  for x in Liste:",
        "    geompy.addToStudy(x[0],x[1])", 
        "    gg.createAndDisplayGO(O_id)",
        "    gg.setDisplayMode(O_id,1)",
        
        VPiq+"M= smesh.Mesh("+ Vxr +")",   
        "Regular_TUBE = "+VPiq+"M.Segment()",
        "Nb_Segments = Regular_TUBE.NumberOfSegments( 1 )",
        "Nb_Segments.SetDistrType( 0 )",
        ]) 
        
        if self.iQUAD:
            CodeAppend(self.CodeS,[
            "Quadratic_Mesh = Regular_TUBE.QuadraticMesh()",
            ])
        
        CodeAppend(self.CodeS,[
        VPiq+"M.Compute()",
        "smesh.SetName("+VPiq+"M , '"+ VPiq +"M')",
        VPiq+"M.GroupOnGeom("+ self.Px+")",
        VPiq+"M.GroupOnGeom("+Pr+")",
        VPiq+"M.GroupOnGeom("+Vxr+")",
        ])
        
        self.LesRigides.append(Vxr)
        self.LesRONDs_iSec.append(Vxr)
        
        exec("self.Les"+self.model+"s.extend([Vxr])")
        self.LTout.append(VPiq)
  
    #----------------------------------------------------------------------    
    def Ajouter_VPoq(self,A,nom,lien):
        """
        Les valeurs de A sont : (Rc,ec,ad1x,ad2x,rc,Lc)
            Rc  :   rayon du piquage
            ec  :   épaisseur du piquage
            ad1x :   1er angle dihèdre
            ad2x  :   2ème angle dihèdre pour des piquages non perpendiculaire
            rc   :   rayon de courbure du joint de soudure
            Lc  :   Longueur collecteur dans chaque direction
        Nom : nom du piquage
        """
        if self.model!="TUBE":AfficherErreur(["VPoq ne fonctionne qu'avec le modèle TUBE!"])
        
        self.Inserer_LesRONDs_iSec()
        [Vd,Secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=Vd
        # RECUPERATION DES INFORMATIONS
        [Rc,ec,ad,bd,rc,Lc] =  ConvNFloat(A,6)

        # INCREMENTATION
        self.nP +=1

        # DEFINITION DES VARIABLES
        [Rp,ep]=self.Secx
        self.Secx=[Rc,ec]
        VPoq = "VPoq" + str(self.nP)

        # PARTIE PRINCIPALE
        # Création d'un tuyau avant celle du piquage
        # qui est de nature différente
        
        # Définition des valeurs pour la modèle 3D du piquage

        Vd3x =  VectDih(Lc,self.Vd1x,self.Vd2x,ad,bd)
        Vd3xo= VectOpp(Vd3x)
        Vd2r = VectRatio(self.Vd2x,Rc)
        Vd2rs =  VectString2(Vd2r)
        Vd3xs =  VectString2(Vd3x)

        VPc1 =  AddVect([[1,self.VPx],[1,Vd2r],[1,Vd3x]]) 
        VPc2 =  AddVect([[1,self.VPx],[1,Vd2r],[-1,Vd3x]]) 
        Pm = "Pm_"+str(self.nP)
        Pc1 = nom+"_1"
        Pc2 = nom+"_2"
        Vxm = "Vxm_"+str(self.nP)
        Vmc1 = "Vmc1_"+str(self.nP)
        Vmc2 = "Vmc2_"+str(self.nP)   
        self.DicP[Pc1] =  [[self.Vd2x,Vd3x],self.Secx,VPc1,VPoq,"TUBE","",1,self.Temp,self.Press]  
        self.DicP[Pc2] =  [[self.Vd2x,Vd3xo],self.Secx,VPc2,VPoq,"TUBE","",1,self.Temp,self.Press] 

        CodeAppend(self.CodeS,[
        #
        "try:",
        "  #Piquage 1D",
        "  print \"Piquage 1D\"",
        "  Liste=[]",
        "  Rp = "+str(Rp),
        "  ep = "+str(ep),
        "  Rc = "+str(Rc),
        "  ec = "+str(ec),
        "  Lc="+str(Lc),
        
        "  Px ="+self.Px,
        
        "  Pm = geompy.MakeVertexWithRef(Px,"+Vd2rs+")",
        "  "+Pm+"=Pm",
        "  Liste.append([Pm,\""+Pm+"\"])",  
        
        "  Vxm = geompy.MakeVector(Px,Pm)",
        "  "+Vxm+"=Vxm",
        "  Liste.append([Vxm,\""+Vxm+"\"])", 
        
        "  Vd3x = geompy.MakeVectorDXDYDZ("+Vd3xs+")",

        "  Pc1 = geompy.MakeTranslationVectorDistance(Pm,Vd3x,Lc)",
        "  "+Pc1+"=Pc1",
        "  Liste.append([Pc1,\""+Pc1+"\"])", 

        "  Vmc1 = geompy.MakeVector(Pm,Pc1)",
        "  "+Vmc1+"=Vmc1",
        "  Liste.append([Vmc1,\""+Vmc1+"\"])", 
        
        "  Pc2 = geompy.MakeTranslationVectorDistance(Pm,Vd3x,-Lc)",
        "  "+Pc2+"=Pc2",
        "  Liste.append([Pc2,\""+Pc2+"\"])", 

        "  Vmc2 = geompy.MakeVector(Pm,Pc2)",
        "  "+Vmc2+"=Vmc2",
        "  Liste.append([Vmc2,\""+Vmc2+"\"])", 
        
 
        "  VPoq=geompy.MakeCompound(["+Vxm+","+Vmc1+","+Vmc2+"])",
        "  "+VPoq+"=VPoq",
        "  Liste.append([VPoq,\""+VPoq+"\"])", 


    #BUG : Salome n'accepte pas que j'utilise plusieurs fois la variable C !

        "  Cpe = geompy.MakeCircle(Pc2,Vd3x,Rc)",
        "  Liste.append([Cpe,\"Cpe\"])",
       
        "  Cpi = geompy.MakeCircle(Pc2,Vd3x,Rc-ec)",
        "  Liste.append([Cpi,\"Cpi\"])",
        
        "  S = geompy.MakeFaceWires([Cpe,Cpi], 1)",
        "  VPiq3D = geompy.MakePrismVecH(S, Vd3x, 2*Lc)",

        "  Liste.append([VPiq3D,\"VPiq3D\"])",

        "  VPiq3D.SetColor(SALOMEDS.Color("+Couleur["TUBE"]+"))",
        "  "+VPoq+"3D= VPiq3D",
        "  VPiq3D_id = geompy.addToStudy(VPiq3D,\""+VPoq+"3D\")",
        "  gg.createAndDisplayGO(VPiq3D_id)",
        "  gg.setDisplayMode(VPiq3D_id,1)",
        
        "  for x in Liste:",
        "    geompy.addToStudyInFather(VPiq3D,x[0],x[1])",
      
        "except:",
        "  print \"Erreur VPiq : geometrie\"",
        "  for x in Liste:",
        "    geompy.addToStudy(x[0],x[1])", 
        "    gg.createAndDisplayGO(O_id)",
        "    gg.setDisplayMode(O_id,1)",
        
        VPoq+"M= smesh.Mesh("+ VPoq +")",   
        "Regular_TUBE = "+VPoq+"M.Segment()",
        "Nb_Segments = Regular_TUBE.NumberOfSegments( 1 )",
        "Nb_Segments.SetDistrType( 0 )",
        ]) 
        
        if self.iQUAD:
            CodeAppend(self.CodeS,[
            "Quadratic_Mesh = Regular_TUBE.QuadraticMesh()",
            ])
        
        CodeAppend(self.CodeS,[
        VPoq+"M.Compute()",
        "smesh.SetName("+VPoq+"M , '"+ VPoq +"M')",
        VPoq+"M.GroupOnGeom("+ self.Px+")",
        VPoq+"M.GroupOnGeom("+Pc1+")",
        VPoq+"M.GroupOnGeom("+Pc2+")",
        VPoq+"M.GroupOnGeom("+Vmc1+")",
        VPoq+"M.GroupOnGeom("+Vmc2+")",
        VPoq+"M.GroupOnGeom("+Vxm+")",
        ])
        
        self.LesRONDs_iSec.extend([Vmc1,Vmc2,Vxm])
        if self.iTemp : self.LesVs_iTemp.extend([Vmc1,Vmc2])
        if self.iPress : self.LesVs_iPress.extend([Vmc1,Vmc2])

        self.LesVs_iMat.extend([Vmc1,Vmc2]) 
        self.LesRigides.append(Vxm)
        
        exec("self.Les"+self.model+"s.extend([Vmc1,Vmc2,Vxm])")
  
        self.LTout.append(VPoq)

    #---------------------------------------------------------------------------
    def Ajouter_Vanne(self,A,nom,lien):
        
        [Vdx,self.Secx,VPx,Vx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=Vdx
        # RECUPERATION DES INFOS
        [Lv,masse,h,ad]=ConvNFloat(A,4)
        [R,e]=self.Secx
        
        # INCREMENTATION
        self.nP += 1    
        
        # DEFINITION DES VARIABLES
        Pn = "Pn" + str(self.nP)
        Pg = "Pg" + str(self.nP)
        Pm = "Pm" + str(self.nP)
        Va = "Va" + str(self.nP)
        Vb = "Vb" + str(self.nP)
        Vmg = "Vmg" + str(self.nP)
        Vanne = "Vanne"+str(self.nP)

        # PARTIE PRINCIPALE
       
        #Vecteur indiquant le centre de gravité à partir du centre
        Vh=VectDih(h,self.Vd1x,self.Vd2x,ad,0)
        Vhs=VectString2(Vh) 
        Vd2 =VectRatio(self.Vd2x,Lv/2)
        Vd2s =VectString2( Vd2 )
        self.VPx =  AddVect([[1,VPx],[2,Vd2]]) 

        # Infos sur le point nommé
        if lien != "" : Ajouter_Liaison(lien)
        if nom != "":
            Pn = nom
        self.DicP[Pn] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,Vanne,self.model,"",self.SIF,self.Temp,self.Press]
        
        exc=1
        if h < 1E-3: exc = 0
        
        CodeAppend(self.CodeS,[
        "  #",
        "try:",
        "  print(\"Ajout de la Vanne : "+ Vanne + "\")", 
        "  R ="+str(R),
        "  Lv = "+str(Lv),
        "  Px = "+ self.Px,
        "  Liste=[]",
        
        "  Pm = geompy.MakeVertexWithRef(Px," +Vd2s + ")",
        "  "+Pm+ " = Pm",
        "  Liste.append([Pm,\""+Pm+"\"])",
        
        "  Pn = geompy.MakeVertexWithRef(Pm," + Vd2s + ")",
        "  "+Pn+"=Pn",
        "  Liste.append([Pn,\""+Pn+"\"])",    
        
        "  Va= geompy.MakeVector(Px,Pm)",
        "  "+Va+"=Va",
        "  Liste.append([Va,\""+Va+"\"])",
        
        "  Vb = geompy.MakeVector(Pm,Pn)", 
        "  "+Vb+"=Vb",
        "  Liste.append([Vb,\""+Vb+"\"])",
        
        "  Pg= geompy.MakeVertexWithRef(Pm,"+Vhs+")",
        "  "+Pg +"= Pg",
        "  Liste.append([Pg,\""+Pg+"\"])",
        ])
        
        if exc:    
            CodeAppend(self.CodeS,[
            "  Vmg = geompy.MakeVector(Pm,Pg)",
            "  "+Vmg + " = Vmg",
            "  Liste.append([Vmg,\""+Vmg+"\"])",
            "  Vanne= geompy.MakeCompound([" + Va + "," + Vb + "," + Vmg + "])",
            ])
        else:
            CodeAppend(self.CodeS,[
            "  Vanne= geompy.MakeCompound([" + Va + "," + Vb + "])",
            ])    
             
        
        CodeAppend(self.CodeS,[
        
        "  "+Vanne + "= Vanne",
        "  Liste.append([Vanne,\""+Vanne+"\"])",     

        "  # ",
        "  VanneA = geompy.MakeCone(Px,Va,R,R*0.1," + str(Lv/2) + ")",
        "  Liste.append([VanneA,\"VanneA\"])",     
        
        "  VanneB = geompy.MakeCone(Pm,Vb,R*0.1,R," + str(Lv/2) + ")",
        "  Liste.append([VanneB,\"VanneB\"])", 
        
        "  Vanne3D = geompy.MakeCompound([VanneA, VanneB])",
        "  Vanne3D.SetColor(SALOMEDS.Color("+Couleur["Vanne"]+"))",
        "  Vanne3D_id = geompy.addToStudy(Vanne3D,\"" + Vanne+"3D\")",
        "  gg.createAndDisplayGO(Vanne3D_id)",
        "  gg.setDisplayMode(Vanne3D_id,1)"])
        
        if exc:
            CodeAppend(self.CodeS,[
            "  CercleExt = geompy.MakeCircle("+Pm+",Vmg,R/4)",
            "  Liste.append([CercleExt ,\"CercleExt\"])",
            "  S = geompy.MakeFaceWires([CercleExt], 1)",
            "  Liste.append([S ,\"S\"])",
            "  Pipe = geompy.MakePipe( S ,"+Vmg+")",
            "  Pipe.SetColor(SALOMEDS.Color("+Couleur["Masse"]+"))",
            "  Pipe_id = geompy.addToStudyInFather(Vanne3D,Pipe,\"" + Vanne+"3D\")",
            "  gg.createAndDisplayGO(Pipe_id)",
            "  gg.setDisplayMode(Pipe_id,1)",
            ])
            
        CodeAppend(self.CodeS,[ 
        "  for x in Liste:",
        "       geompy.addToStudyInFather(Vanne3D,x[0],x[1])",
        
        "  #",
        "  # Création du maillage",
        "  VanneM = smesh.Mesh(Vanne)",
        "  Regular_TUBE = VanneM.Segment()",
        "  Nb_Segments = Regular_TUBE.NumberOfSegments(1)",
        "  Nb_Segments.SetDistrType( 0 )",
        ]) 
        
        if self.iQUAD or self.model=="TUYAU3M":
            CodeAppend(self.CodeS,[
            "  Quadratic_Mesh = Regular_TUBE.QuadraticMesh()",
            ])
        
        CodeAppend(self.CodeS,[ 
        "  smesh.SetName(VanneM , '" + Vanne + "')",
        "  L1=[Pm,Pn,Va,Vb,Vmg,Vanne]",
        "  for x in L1:",
        "    VanneM.Group(x)",
        "  VanneM.Group(Pg)",

        "  VanneM.Compute()",
        "  conodes = VanneM.FindCoincidentNodes( 1e-05 )",
        "  VanneM.MergeNodes(conodes)",
        "  "+Vanne+"M=VanneM",
        
        "except:",
        "  print(\"Erreur Vanne\")",
        "  for x in Liste:",
        "    geompy.addToStudy(x[0],x[1])",
        "  gg.createAndDisplayGO(O_id)",
        "  gg.setDisplayMode(O_id,1)", 
        ])
        
            
#BUG :  la masse de la vanne ne peut pas être ajoutée au bout d'une liaison 
#       rigide, il faut revenir à une poutre avec un matériau rigide.      
#        self.LesLis.append(Vmg)    
#        self.LesRONDx4s_iSec.extend([Va,Vb])  
#        exec("self.Les"+self.model+"s.extend([Va,Vb])")

        self.LesRigides.append(Vmg)
        self.LesRONDx4s_iSec.extend([Va,Vb,Vmg])
        
        exec("self.Les"+self.model+"s.extend([Va,Vb,Vmg])")

        self.LesVs_iMat.extend([Va,Vb])
        if self.iTemp: self.LesVs_iTemp.extend([Va,Vb])
        if self.iPress: self.LesVs_iPress.extend([Va,Vb])
        
        self.LesMasses.append(Pg)
        
   
        Lx =  TrouverLigne(self.CodeA,"#MASSE_DISCRET")
        CodeInsertI(self.CodeA,Lx,2,[
        "_F(",
        "   GROUP_MA='"+Pg+"A',",
        "   CARA='M_T_D_N',",
        "   VALE=("+str(masse/1000)+"),",
        "),",
        ])
        
        self.Ajouter_GENE()
        
        self.LTout.append(Vanne)
        self.Px = Pn
        
        
            
            
    #---------------------------------------------------------------------------
    def Ajouter_V(self,A,nom,lien) :
        if self.model=="3D":
            exec("self.Ajouter_V_"+self.forme+"_3D(A,nom,lien)")
            
        elif self.model in LesModeles_ROND:
            self.Ajouter_V_ROND_1D(A,nom,lien)
            
        elif self.model in ["POUTRE_RECTANGLE"]:
            self.Ajouter_V_RECT_1D(A,nom,lien)  
            
        elif self.model in ["POUTRE"]:
            self.Ajouter_V_POUT_1D(A,nom,lien)  
                  
        else:
            AfficherErreur(["Model inconu"])
            
        
    #---------------------------------------------------------------------------
    def Ajouter_V_ROND_3D(self,A,nom,lien):

        [Vd,self.Secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=Vd

        [dx,dy,dz,n]=ConvNInt(A,4)
        dV=[dx,dy,dz]
        if n == 0 : n=1
        
        Vd2s =  VectString2(dV)
        Lc = NormVect(dV)
        Vd2o =  VectOpp(dV)
        Vd2os =  VectString2(Vd2o)
        e=self.Secx[1]
        R=self.Secx[0]

        self.nP += 1
        
        Pn = "Pn"+str(self.nP)
        V3D = "V3D"+str(self.nP)
        V3DSx = V3D+"Sx"
        V3DSx2 = V3D+"Sx2"
        self.VPx =  AddVect([[1,VPx],[1,dV]])
        
        # Infos sur le point nommé
        self.Ajouter_Liaison(lien)
        if nom != "": Pn = nom
        self.DicP[Pn] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,V3D,"3D",V3DSx2,self.SIF,self.Temp,self.Press]
        
        CodeAppend(self.CodeS,[
        "try:",
        "  print(\"Ajout du tube  "+ V3D + "\")",  
        "  Liste=[]",    
        "  # Création d'un cylindre maillable en réglé",
        "  Px="+self.Px,
        "  R="+str(R),
        "  e="+str(e),
        "  Lc="+str(Lc),
        "  n = "+str(n),
        "  Lmax = max(Lc,2*R)",

        "  Pn = geompy.MakeVertexWithRef(Px,"+Vd2s+")",
        "  "+Pn+" = Pn",
        "  Liste.append([Pn,\""+Pn+"\"])",
        
        "  Vd2x = geompy.MakeVector(Px,Pn)",
        "  Liste.append([Vd2x,\"Vd2x\"])",    
        
        "  C1 = geompy.MakeCircle(Px,Vd2x,R)",
        "  Liste.append([C1,\"C1\"])",
        
        "  C2 = geompy.MakeCircle(Px,Vd2x,R-e)",
        "  Liste.append([C2,\"C2\"])",
        
        "  Face1 = geompy.MakeFaceWires([C1, C2], 1)",
        "  Liste.append([Face1,\"Face1\"])",
        
        "  V3D = geompy.MakePrismVecH(Face1, Vd2x, Lc)",
        "  Liste.append([V3D,\"V3D\"])",    
        
        "  Vd2xo = geompy.MakeVector(Pn,Px)",
        "  Sx0 = geompy.GetFaceByNormale(V3D,Vd2xo)",
        "  Liste.append([Sx0,\"Sx0\"])",
        
        "  Lx = geompy.SubShapeAllSorted(Sx0, geompy.ShapeType[\"VERTEX\"])",
        "  p = Lx[0]",
        "  Liste.append([p,\"p\"])",
        
        "  Vd3x = geompy.MakeVector(Px,p)",
        "  Liste.append([Vd3x,\"Vd3x\"])",
        
        "  Vd4x = geompy.MakeRotation(Vd3x,Vd2x,math.pi/2)",
        "  Liste.append([Vd4x,\"Vd4x\"])",

        "  plan = geompy.MakePlane(Px,Vd4x,Lmax*5)",
        "  Liste.append([plan,\"plan1\"])",
        
        "  "+V3D+" = geompy.MakeHalfPartition(V3D, plan)",
        "  V3D_id = geompy.addToStudy("+V3D+",\""+V3D+"\")", 
        "  gg.createAndDisplayGO(V3D_id)",   
        "  gg.setDisplayMode(V3D_id,1)",
     
    #	    "  plan = geompy.MakePlane(Px,Vd3x,Lmax*5)",
    #	    "  Liste.append([plan,\"plan2\"])",  
    #BUG	 il faut utiliser un vecteur ici Vd2x pour définir le plan de recherche.
    # en utilisant les plans définis ci-dessus ça ne marche pas.    
        
        "  LSx = geompy.GetShapesOnPlane("+V3D+",geompy.ShapeType[\"FACE\"],Vd2x,GEOM.ST_ON)",
        "  "+V3D+"Sx = geompy.MakeCompound(LSx)",
        "  geompy.addToStudy("+V3D+"Sx,\""+V3D+"Sx\")",

        "  LSx2 = geompy.GetShapesOnPlane("+V3D+",geompy.ShapeType[\"FACE\"],Vd2xo,GEOM.ST_ON)",
        "  "+V3D+"Sx2 = geompy.MakeCompound(LSx2)",
        "  Liste.append(["+V3D+"Sx2,\""+V3D+"Sx2\"])", 

        "  po1 = geompy.MakeTranslationVectorDistance(Px,Vd3x,R-e/2)",
        "  Liste.append([po1,\"po1\"])",

        "  E1 = geompy.GetShapesNearPoint("+V3D+",po1 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E1,\"E1\"])",

        "  po1 = geompy.MakeTranslationVectorDistance(Px,Vd3x,R)",
        "  po2 = geompy.MakeTranslationVectorDistance(po1,Vd2x,Lc/2)",
        "  Liste.append([po2,\"po2\"])", 

        "  n2=int(n*Lc/(2*e))",
        "  if n2 <1: n2=1",
        "  E2 = geompy.GetShapesNearPoint("+V3D+",po2 ,geompy.ShapeType[\"EDGE\"],1)",
        "  Liste.append([E2,\"E2\"])",

        "  for x in Liste :",
        "     geompy.addToStudyInFather("+V3D+",x[0],x[1])",
        
        "except:",
        "  print(\"    =>ERREUR\")",
        "  for x in Liste :",
        "     geompy.addToStudy(x[0],x[1])",
        "  gg.createAndDisplayGO(O_id)",
        "  gg.setDisplayMode(O_id,1)",

         # Maillage
        "try:",
        "  print \"  Maillage\"",
        "  "+V3D+"M = smesh.Mesh("+V3D+")",
        "  "+V3D+"M.Quadrangle()",
        "  Hexa_3D = smesh.CreateHypothesis('Hexa_3D')",
        "  "+V3D+"M.AddHypothesis(Hexa_3D)",
        "  n0=int(n*math.pi*R/(2*e))",
        "  if n0<4: n0=4",
        "  Regular_TUBE_0 = "+V3D+"M.Segment()",
        "  Regular_TUBE_0.NumberOfSegments(n0)",
        
        "  Regular_TUBE_1 = "+V3D+"M.Segment(geom=E1)",
        "  Regular_TUBE_1.NumberOfSegments("+str(n)+")",
        "  Regular_TUBE_1.Propagation()",
        
        "  Regular_TUBE_2 = "+V3D+"M.Segment(geom=E2)",
        "  Regular_TUBE_2.NumberOfSegments(n2)",
        "  Regular_TUBE_2.Propagation()",
        "  "+V3D+"M.Compute()",
       
        "  smesh.SetName("+V3D+"M,\""+V3D+"\")",
        "  "+V3D+"M.GroupOnGeom("+V3D+")",
        "  "+V3D+"M.GroupOnGeom("+V3D+"Sx)",
        "  "+V3D+"M.GroupOnGeom("+V3D+"Sx2)",

        "except:",
        "  print(\"    =>ERREUR\")",
        ])

        self.Les3Ds.extend([V3D,V3D+"Sx",V3D+"Sx2"])
        self.LesVs_iMat.extend([V3D,V3D+"Sx",V3D+"Sx2"])

       
        
        if modelx in  ["TUBE","TUYAU3M","TUYAU6M"]:         
                Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_POUTRE")
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   OPTION='3D_POU',",
                "   GROUP_MA_1 ='"+V3D+"Sx',",
                "   GROUP_NO_2 ='"+self.Px+"',",
                "),",
                ])
                
        elif modelx in  ["TUYAU3M","TUYAU6M"]:          
                Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_TUYAU")
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   OPTION='3D_TUYAU',",
                "   GROUP_MA_1 ='"+V3D+"Sx',",
                "   GROUP_NO_2 ='"+self.Px+"',",
                "),",
                ])

        elif modelx=="3D":
            Lx = TrouverLigne(self.CodeA,"#LIAISON_MAIL")
            CodeAInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   TYPE_RACCORD='MASSIF',",
            "   GROUP_MA_ESCL='"+nomx+"Sx2',",
            "   GROUP_MA_MAIT='"+V3D+"Sx',",
            "),",
            ]) 

        	    
        self.LTout.append(V3D)
        self.Px = Pn
        #self.Last = [Pn,V3D,self.Vd2x,lien,self.model]
        

    #---------------------------------------------------------------------------
    def Ajouter_V_ROND_1D(self,A,nom,lien):

        [Vdx,secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        Px=self.Px
        secx=self.Secx
        model=self.model
        Vd1x=self.Vd1x
        Vd2x=self.Vd2x

        Vd3x = ConvNFloat(A,3)
        Lc=NormVect(Vd3x)

        self.nP += 1
        nP=self.nP
        
        Pn = self.NommerNoeud(nom)

        V = self.model[:3]+str(nP)
        self.V = V
        
        VPx =  AddVect([[1,self.VPx],[1,Vd3x]])   
        self.VPx=VPx
        
        Vd3xs = VectString2(Vd3x)
        
        CodeAppend(self.CodeS,[
        "try:",
        "  print(\"Creation de: "+ V + "\")",
        "  Vd2x=geompy.MakeVectorDXDYDZ("+Vd3xs+")",
        "  Liste=[]",
        "  "+Pn+"= geompy.MakeTranslationVectorDistance("+Px+",Vd2x,"+str(Lc)+")",
        "  Liste.append(["+Pn+",\""+Pn+"\"])",
        "  "+V+"= geompy.MakeVector("+Px+","+Pn+")",
        "  Liste.append(["+V+",\""+V+"\"])",

        "  CercleExt = geompy.MakeCircle("+Px+",Vd2x,R)",
        "  Liste.append([CercleExt ,\"CercleExt\"])",
        "  if R>e:",
        "      CercleInt = geompy.MakeCircle("+Px+",Vd2x,R-e)",
        "      Liste.append([CercleInt ,\"CercleInt\"])",
        
        "      S = geompy.MakeFaceWires([CercleExt, CercleInt], 1)",
        "      Liste.append([S ,\"S\"])",

        "  else:",
        "      S = geompy.MakeFaceWires([CercleExt], 1)",
        "      Liste.append([S ,\"S\"])",

        "  Pipe = geompy.MakePipe( S ,"+V+")",
        "  Pipe.SetColor(SALOMEDS.Color("+Couleur[self.model]+"))",
        "  Pipe_id=geompy.addToStudy(Pipe,\""+ V +"_3D\")",
        "  gg.createAndDisplayGO(Pipe_id)",
        "  gg.setDisplayMode(Pipe_id,1)",

        "  for x in Liste :",
        "     geompy.addToStudyInFather(Pipe,x[0],x[1])",

        "except:",
        "  ERREUR=True",
        "  print (\"   =>ERREUR géométrie!\")",
        "  for x in Liste :",
        "     geompy.addToStudy(x[0],x[1])",
        
        	    
        "try:",
        "  "+ V+"M = smesh.Mesh("+  V +")",
        "  Decoupage = "+ V+"M.Segment()",
        ]) 
        
        if self.model in ["BARRE","RESSORT"]:
            CodeAppend(self.CodeS,[
            "  Decoupage.NumberOfSegments("+str(1)+")",
            ])
        else:
            CodeAppend(self.CodeS,[
            "  Decoupage.NumberOfSegments("+str(self.NbElement)+")",
            ]) 
        
        if self.iQUAD or self.model in ["TUYAU3M","TUYAU6M"]:
            CodeAppend(self.CodeS,[
            "  Quadratic_Mesh = Decoupage.QuadraticMesh()",
            ])
        
        CodeAppend(self.CodeS,[ 
        "  smesh.SetName("+ V+"M,'"+V+"')",
        "  "+V+"M.Compute()",
        "  "+V+"M.GroupOnGeom("+ Px+")",
        "  "+V+"M.GroupOnGeom("+Pn+")",
        "  "+V+"M.GroupOnGeom("+V+")",
        "except:",
        "  ERREUR=True",
        "  print (\"   =>ERREUR maillage!\")",
        ]) 
    

        if self.LastCd not in ["P","Px","Pxvr"]:
            if VerifierColinea(self.Vd2x,Vd3x) == 0 : 
                self.DicP[Pn] =  [[Vd2x,Vd3x],secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
            else:
                self.DicP[Pn] =  [[Vd1x,Vd2x],secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
        else:
            self.DicP[Pn] =  [[Vd1x,Vd3x],secx,VPx,V,model,"",self.SIF,self.Temp,self.Press]
            self.DicP[Px] =  [[Vd1x,Vd3x],secx,VPx,V,model,"",SIFx,self.Temp,self.Press]
            
      
        if self.model not in ["RESSORT"]:
        
            if self.iTemp : self.LesVs_iTemp.append(V)
            if self.iPress : self.LesVs_iPress.append(V)
            self.LesRONDs_iSec.append( V)    

            if modelx=="3D":
                if self.model=="TUBE":
                    Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_POUTRE")
                    CodeInsertI(self.CodeA,Lx,2,[
                    "_F(",
                    "   OPTION='3D_POU',",
                    "   GROUP_MA_1 ='"+Sec3Dx+"',",
                    "   GROUP_NO_2 ='"+Px+"',",
                    "),",
                    ])   
                elif self.model in ["TUYAU3M","TUYAU6M"]:
                    Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_TUYAU")
                    CodeInsertI(self.CodeA,Lx,2,[
                    "_F(",
                    "   OPTION='3D_TUYAU',",
                    "   GROUP_MA_1 ='"+Sec3Dx+"',",
                    "   GROUP_NO_2 ='"+Px+"',",
                    "),",
                    ]) 
            
            if self.model in ["TUYAU3M","TUYAU6M"]:
                self.Ajouter_GENE()
                if self.iPress : self.LesVs_iPress.append(V)
            
            exec("self.Les"+self.model+"s.append(V)")    
        
        else:
            self.LesRESSORTs.append([V,self.raideur])
        
        self.LesVs_iMat.append(V)    
        self.LTout.append(V)   
        self.Px=self.Pn
        self.SIF=1
        self.Vd2x=Vd3x
        self.Ajouter_Liaison(lien)
        
        
        
    #---------------------------------------------------------------------------
    def Ajouter_V_RECT_1D(self,A,nom,lien):

        [Vdx,secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        Px=self.Px
        [Hy,Hz,ey,ez,angle]=self.Secx
        
        iRectPlein=False
        if ey==0 and ez==0 : iRectPlein=True
        
        L1=Hy/2
        L2=Hz/2
        L2s=str(L2)
        L1s=str(L1)
        Li2s=str(L2-ey)
        Li1s=str(L1-ez)
        
        model=self.model
        Vd1x=self.Vd1x
        Vd2x=self.Vd2x

        Vd3x = ConvNFloat(A,3)
        Lc=NormVect(Vd3x)

        self.nP += 1
        nP=self.nP
        
        Pn = self.NommerNoeud(nom)

        V = "RECT"+str(nP)
        self.V = V
        
        VPxs=VectString2(self.VPx)
        
        VPx0=self.VPx
        VPx =  AddVect([[1,VPx0],[1,Vd3x]])   
        self.VPx=VPx
        
        Vd3xs = VectString2(Vd3x)
        vi3=VectNorm(Vd3x)
        vi3s=VectString2(vi3)
        
        if VerifierColinea(vi3,[0,0,1]) == 0 :
            vj3=ProdVect([0,0,1],vi3)
            vk3=ProdVect(vi3,vj3)
            vj3r=RotVect(vj3,vi3,self.angleP)
            vk3r=RotVect(vk3,vi3,self.angleP)
            
        else:
            vj3r=RotVect([1,0,0],[0,0,1],self.angleP)
            vk3r=RotVect([0,1,0],[0,0,1],self.angleP)
                
        vj3rs=VectString2(vj3r)
        vk3rs=VectString2(vk3r)
        
        CodeAppend(self.CodeS,[
        "try:",
        "   print(\"Creation de: "+ V + "\")",
        "   Vd2x=geompy.MakeVectorDXDYDZ("+Vd3xs+")",
        "   Liste=[]",
        "   "+Pn+"= geompy.MakeTranslationVectorDistance("+Px+",Vd2x,"+str(Lc)+")",
        "   Liste.append(["+Pn+",\""+Pn+"\"])",
        "   "+V+"= geompy.MakeVector("+Px+","+Pn+")",
        "   Liste.append(["+V+",\""+V+"\"])",
        ]) 
        if iRectPlein:
            CodeAppend(self.CodeS,[
            "   W1 = geompy.MakeSketcher(\"Sketcher: F "+L1s+" "+L2s+": TT -"+L1s+" "+L2s+": TT -"+L1s+" -"+L2s+": TT "+L1s+" -"+L2s+": WW\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   S = geompy.MakeFaceWires([W1], 1)",
            ])
        else:
            CodeAppend(self.CodeS,[
            "   W1 = geompy.MakeSketcher(\"Sketcher: F "+L1s+" "+L2s+": TT -"+L1s+" "+L2s+": TT -"+L1s+" -"+L2s+": TT "+L1s+" -"+L2s+": WW\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            
            "   W2 = geompy.MakeSketcher(\"Sketcher: F "+Li1s+" "+Li2s+": TT -"+Li1s+" "+Li2s+": TT -"+Li1s+" -"+Li2s+": TT "+Li1s+" -"+Li2s+": WW\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   S = geompy.MakeFaceWires([W1, W2], 1)",
            ])
            
        CodeAppend(self.CodeS,[
        "   Liste.append([S ,\"S\"])",
        "   Pipe = geompy.MakePipe( S ,"+V+")",
        "   Pipe.SetColor(SALOMEDS.Color("+Couleur["TUBE"]+"))",
        "   Pipe_id=geompy.addToStudy(Pipe,\""+ V +"_3D\")",
        "   gg.createAndDisplayGO(Pipe_id)",
        "   gg.setDisplayMode(Pipe_id,1)",

        "   for x in Liste :",
        "       geompy.addToStudyInFather(Pipe,x[0],x[1])",

        "except:",
        "   ERREUR=True",
        "   print (\"   =>ERREUR géométrie!\")",
        "   for x in Liste :",
        "       geompy.addToStudy(x[0],x[1])",
        
        	    
        "try:",
        "   "+ V+"M = smesh.Mesh("+  V +")",
        "   Decoupage = "+ V+"M.Segment()",
        "   Decoupage.NumberOfSegments("+str(self.NbElement)+")",
        "   smesh.SetName("+ V+"M,'"+V+"')",
        "   "+V+"M.Compute()",
        "   "+V+"M.GroupOnGeom("+ Px+")",
        "   "+V+"M.GroupOnGeom("+Pn+")",
        "   "+V+"M.GroupOnGeom("+V+")",
        "except:",
        "   ERREUR=True",
        "   print (\"   =>ERREUR maillage!\")",
        ]) 
        
        # Orientation de la section
        LTex=[
        "_F(    CARA='VECT_X_Y',",
        "       VALE=("+vi3s+","+vj3rs+"),",
        "       GROUP_MA=('"+V+"' )",
        "),"
        ]
        Lx=TrouverLigne(self.CodeA,"#ORIENTATION")
        CodeInsertI(self.CodeA,Lx,2,LTex)
        
        #Ajout de l'angle à la section
        self.Ajouter_Liaison(lien)

        if self.LastCd not in ["P","Px","Pxvr"]:
            if VerifierColinea(self.Vd2x,Vd3x) == 0 : 
                self.DicP[Pn] =  [[Vd2x,Vd3x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
            else:
                self.DicP[Pn] =  [[Vd1x,Vd2x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
        else:
            self.DicP[Pn] =  [[Vd1x,Vd3x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press]
            self.DicP[Px] =  [[Vd1x,Vd3x],self.Secx,VPx0,V,model,"",SIFx,self.Temp,self.Press]
    
        if self.iTemp : self.LesVs_iTemp.append(V)
        if self.iPress : self.LesVs_iPress.append(V)
            
        self.LesRECTs_iSec.append(V)
        self.LesVs_iMat.append(V)
        self.LTout.append(V)
        
        if modelx=="3D":
                Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_POUTRE")
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   OPTION='3D_POU',",
                "   GROUP_MA_1 ='"+Sec3Dx+"',",
                "   GROUP_NO_2 ='"+self.Px+"',",
                "),",
                ])   
  
        self.LesPOUTREs.append(V)
        
        self.Px=self.Pn
        self.SIF=1

    #---------------------------------------------------------------------------
    def Ajouter_V_POUT_1D(self,A,nom,lien):

        [Vdx,secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        Px=self.Px
        
        model=self.model
        Vd1x=self.Vd1x
        Vd2x=self.Vd2x

        Vd3x = ConvNFloat(A,3)
        Lc=NormVect(Vd3x)

        self.nP += 1
        nP=self.nP
        
        Pn = self.NommerNoeud(nom)

        V = "POUT"+str(nP)
        self.V = V
        
        VPxs=VectString2(self.VPx)
        
        VPx0=self.VPx
        VPx =  AddVect([[1,VPx0],[1,Vd3x]])   
        self.VPx=VPx
        
        Vd3xs = VectString2(Vd3x)
        vi3=VectNorm(Vd3x)
        vi3s=VectString2(vi3)
        
        if VerifierColinea(vi3,[0,0,1]) == 0 :
            vj3=ProdVect([0,0,1],vi3)
            vk3=ProdVect(vi3,vj3)
            vj3r=RotVect(vj3,vi3,self.angleP)
            vk3r=RotVect(vk3,vi3,self.angleP)
            
        else:
            vj3r=RotVect([1,0,0],[0,0,1],self.angleP)
            vk3r=RotVect([0,1,0],[0,0,1],self.angleP)
                
        vj3rs=VectString2(vj3r)
        vk3rs=VectString2(vk3r)
        
        CodeAppend(self.CodeS,[
        "try:",
        "   print(\"Creation de: "+ V + "\")",
        "   Vd2x=geompy.MakeVectorDXDYDZ("+Vd3xs+")",
        "   Liste=[]",
        "   "+Pn+"= geompy.MakeTranslationVectorDistance("+Px+",Vd2x,"+str(Lc)+")",
        "   Liste.append(["+Pn+",\""+Pn+"\"])",
        "   "+V+"= geompy.MakeVector("+Px+","+Pn+")",
        "   Liste.append(["+V+",\""+V+"\"])",
        "   W1 = geompy.MakeSketcher(\"Sketcher: "+LesSections[self.Secx][1]+"\",",
        "       [   "+VPxs+",",
        "           "+vi3s+",",
        "           "+vj3rs+"]",
        "   )",
        "   S = geompy.MakeFaceWires([W1], 1)",
        "   Liste.append([S ,\"S\"])",
        "   Pipe = geompy.MakePipe( S ,"+V+")",
        "   Pipe.SetColor(SALOMEDS.Color("+Couleur["TUBE"]+"))",
        "   Pipe_id=geompy.addToStudy(Pipe,\""+ V +"_3D\")",
        "   gg.createAndDisplayGO(Pipe_id)",
        "   gg.setDisplayMode(Pipe_id,1)",

        "   for x in Liste :",
        "       geompy.addToStudyInFather(Pipe,x[0],x[1])",

        "except:",
        "   ERREUR=True",
        "   print (\"   =>ERREUR géométrie!\")",
        "   for x in Liste :",
        "       geompy.addToStudy(x[0],x[1])",
        
        	    
        "try:",
        "   "+ V+"M = smesh.Mesh("+  V +")",
        "   Decoupage = "+ V+"M.Segment()",
        "   Decoupage.NumberOfSegments("+str(self.NbElement)+")",
        "   smesh.SetName("+ V+"M,'"+V+"')",
        "   "+V+"M.Compute()",
        "   "+V+"M.GroupOnGeom("+ Px+")",
        "   "+V+"M.GroupOnGeom("+Pn+")",
        "   "+V+"M.GroupOnGeom("+V+")",
        "except:",
        "   ERREUR=True",
        "   print (\"   =>ERREUR maillage!\")",
        ]) 
        
        # Orientation de la section
        LTex=[
        "_F(    CARA='VECT_X_Y',",
        "       VALE=("+vi3s+","+vj3rs+"),",
        "       GROUP_MA=('"+V+"' )",
        "),"
        ]
        Lx=TrouverLigne(self.CodeA,"#ORIENTATION")
        CodeInsertI(self.CodeA,Lx,2,LTex)
        
        #Ajout de l'angle à la section
        self.Ajouter_Liaison(lien)

        if self.LastCd not in ["P","Px","Pxvr"]:
            if VerifierColinea(self.Vd2x,Vd3x) == 0 : 
                self.DicP[Pn] =  [[Vd2x,Vd3x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
            else:
                self.DicP[Pn] =  [[Vd1x,Vd2x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
        else:
            self.DicP[Pn] =  [[Vd1x,Vd3x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press]
            self.DicP[Px] =  [[Vd1x,Vd3x],self.Secx,VPx0,V,model,"",SIFx,self.Temp,self.Press]
    
        if self.iTemp : self.LesVs_iTemp.append(V)
        if self.iPress : self.LesVs_iPress.append(V)
            
        self.LesPOUTREs_iSec.append(V)
        self.LesVs_iMat.append(V)
        self.LTout.append(V)
        
        if modelx=="3D":
                Lx=TrouverLigne(self.CodeA,"#LIAISON_3D_POUTRE")
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   OPTION='3D_POU',",
                "   GROUP_MA_1 ='"+Sec3Dx+"',",
                "   GROUP_NO_2 ='"+self.Px+"',",
                "),",
                ])   
  
        self.LesPOUTREs.append(V)
        
        self.Px=self.Pn
        self.SIF=1

           

    #---------------------------------------------------------------------------
    def Ajouter_Vd1x(self,A,nom,lien) :
        Vd1xn = VectNum(A)
        [Vdx,Secx,VPx,noma,modela,Sec3D, SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=Vdx
        self.Vd1x = Vd1xn
        Vdx=[Vd1xn,self.Vd2x]
        self.DicP[self.Px]=[Vdx,Secx,VPx,noma,modela,Sec3D,SIFx,Tempx,Pressx]

       
    #---------------------------------------------------------------------------
    def Ajouter_Vd2x(self,A,nom,lien) :
        Vd2xn = VectNum(A)
        [Vdx,Secx,VPx,noma,modela,Sec3D,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        [self.Vd1x,self.Vd2x]=Vdx
        self.Vd2x = Vd2xn
        Vdx=[self.Vd1x,Vd2xn]
        self.DicP[self.Px]=[Vdx,Secx,VPx,noma,modela,Sec3D,SIFx,Tempx,Pressx]

        Vd2xs = VectString2(self.Vd2x)
        CodeAppend(self.CodeS,[
        "Vd2x = geompy.MakeVectorDXDYDZ("+Vd2xs+")",
        ])
        
    #---------------------------------------------------------------------------
    def Ajouter_Vd2xOpp(self,A,nom,lien):
        self.Vd2x = VectOpp(self.Vd2x)
        Vd2xs = VectString2(self.Vd2x)
        CodeAppend(self.CodeS,[
        "Vd2x = geompy.MakeVectorDXDYDZ("+Vd2xs+")",
        ])
        
    #---------------------------------------------------------------------------
    def Ajouter_WireVc(self,A,nom,lien):  
        self.iWireVc=True
        self.Ajouter_Wire(A,nom,lien)   
        self.iWireVc=False
        
    #---------------------------------------------------------------------------
    def Ajouter_Wire(self,A,texte,lien):

        [Vdx,secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        Px=self.Px
        
        model=self.model
        Vd1x=self.Vd1x
        Vd2x=self.Vd2x

        if self.iWireVc:
            [L]=ConvNFloat(A,1)
            Vd3x=VectRatio(self.Vd2x,L)
        else:
            Vd3x = ConvNFloat(A,3)
            
        Lc=NormVect(Vd3x)

        self.nP += 1
        nP=self.nP
        
        Pn = "Pn_"+str(nP)
        self.Pn=Pn

        V = "DIR"+str(nP)
        self.V = V
        
        iFace=False
        if "WF" in texte:
            iFace=True
            nom="FACE"+str(nP)
        else:
            nom="WIRE"+str(nP)
        
        VPxs=VectString2(self.VPx)
        
        VPx0=self.VPx
        VPx =  AddVect([[1,VPx0],[1,Vd3x]])   
        self.VPx=VPx
        
        Vd3xs = VectString2(Vd3x)
        vi3=VectNorm(Vd3x)
        vi3s=VectString2(vi3)
        
        if VerifierColinea(vi3,[0,0,1]) == 0 :
            vj3=ProdVect([0,0,1],vi3)
            vk3=ProdVect(vi3,vj3)
            vj3r=RotVect(vj3,vi3,self.angleP)
            vk3r=RotVect(vk3,vi3,self.angleP)
            
        else:
            vj3r=RotVect([1,0,0],[0,0,1],self.angleP)
            vk3r=RotVect([0,1,0],[0,0,1],self.angleP)
                
        vj3rs=VectString2(vj3r)
        vk3rs=VectString2(vk3r)
        
        texte=texte.replace("&",":")
        
        CodeAppend(self.CodeS,[
        "try:",
        "   Liste=[]",
        "   print(\"Creation de: "+ nom + "\")",
        "   Vd2x=geompy.MakeVectorDXDYDZ("+Vd3xs+")",
        "   "+Pn+"= geompy.MakeTranslationVectorDistance("+Px+",Vd2x,"+str(Lc)+")",
        "   Liste.append(["+Pn+",\""+Pn+"\"])",
        "   "+V+"= geompy.MakeVector("+Px+","+Pn+")",
        "   Liste.append(["+V+",\""+V+"\"])",
       ])
       
        if iFace:
            CodeAppend(self.CodeS,[
            "   wire = geompy.MakeSketcher(\"Sketcher:"+texte+"\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   Liste.append([wire,\"wire\"])",
            "   "+nom+" = geompy.MakeFaceWires([wire], 1)",
            "   LesNo = geompy.ExtractShapes(wire, geompy.ShapeType[\"VERTEX\"], True)",  
            "   Pn1=LesNo[0]",
            "   Liste.append([Pn1,\"Pn1\"])",
            ])
            
        else:
            CodeAppend(self.CodeS,[
            "   "+nom+" = geompy.MakeSketcher(\"Sketcher:"+texte+"\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            
            ])

        CodeAppend(self.CodeS,[
        "   nom_id=geompy.addToStudy("+nom+",\""+ nom +"\")",
        "   gg.createAndDisplayGO(nom_id)",
        "   gg.setDisplayMode(nom_id,1)",

        "   for x in Liste :",
        "       geompy.addToStudyInFather("+nom+",x[0],x[1])",

        "except:",
        "   print (\"   =>ERREUR géométrie!\")",
        "   for x in Liste :",
        "       geompy.addToStudy(x[0],x[1])",
        	    
        ]) 
        
        if iFace:
            CodeAppend(self.CodeS,[
            "try:",
            "   "+nom+"M = smesh.Mesh("+nom+")",
            "   Regular_1D = "+nom+"M.Segment()",
            "   Max_Size_1 = Regular_1D.MaxSize("+str(self.LgElement)+")",
            "   MEFISTO_2D = "+nom+"M.Triangle(algo=smesh.MEFISTO)",
            "   Length_From_Edges_2D = MEFISTO_2D.LengthFromEdges()",
            "   isDone = "+nom+"M.Compute()",
            "   smesh.SetName("+nom+"M.GetMesh(), '"+nom+"M')",
            "   "+nom+"M.GroupOnGeom(wire,'LSURF',SMESH.EDGE)",
            "   "+nom+"M.GroupOnGeom(Pn1,'Pn1',SMESH.NODE)",
            
            
            "except:",
            "   print(\"ERREUR maillage\")",
             ]) 

        
        #Ajout de l'angle à la section
        self.Ajouter_Liaison(lien)

        if self.LastCd not in ["P","Px","Pxvr"]:
            if VerifierColinea(self.Vd2x,Vd3x) == 0 : 
                self.DicP[Pn] =  [[Vd2x,Vd3x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
            else:
                self.DicP[Pn] =  [[Vd1x,Vd2x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
        else:
            self.DicP[Pn] =  [[Vd1x,Vd3x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press]
            self.DicP[Px] =  [[Vd1x,Vd3x],self.Secx,VPx0,V,model,"",SIFx,self.Temp,self.Press]
    
        self.Px=self.Pn
        
        
        
    #---------------------------------------------------------------------------
    def Ajouter_Wire2Dc(self,A,nom,lien):  
        A=VectString(self.Vd2x)
        self.Ajouter_Wire2D(A,nom,lien)
        
        
        
    #---------------------------------------------------------------------------
    def Ajouter_Wire2D(self,A,nom,lien):

        [Vdx,secx,VPx,nomx,modelx,Sec3Dx,SIFx,Tempx,Pressx]=self.DicP[self.Px]
        Px=self.Px
        
        model=self.model
        Vd1x=self.Vd1x
        Vd2x=self.Vd2x

        Vd3x = ConvNFloat(A,3)
        Lc=NormVect(Vd3x)

        self.nP += 1
        nP=self.nP
        
        Pn = "Pn_"+str(nP)
        self.Pn=Pn

        V = "DIR"+str(nP)
        self.V = V
        
        S2D="S2D"+str(nP)
        
        VPxs=VectString2(self.VPx)
        
        VPx0=self.VPx
        VPx =  AddVect([[1,VPx0],[1,Vd3x]])   
        self.VPx=VPx
        VPx2s=VectString2(self.VPx)
        
        Vd3xs = VectString2(Vd3x)
        vi3=VectNorm(Vd3x)
        vi3s=VectString2(vi3)
        
        if VerifierColinea(vi3,[0,0,1]) == 0 :
            vj3=ProdVect([0,0,1],vi3)
            vk3=ProdVect(vi3,vj3)
            vj3r=RotVect(vj3,vi3,self.angleP)
            vk3r=RotVect(vk3,vi3,self.angleP)
            
        else:
            vj3r=RotVect([1,0,0],[0,0,1],self.angleP)
            vk3r=RotVect([0,1,0],[0,0,1],self.angleP)
                
        vj3rs=VectString2(vj3r)
        vk3rs=VectString2(vk3r)
        
        nom=nom.replace("&",":")
        
        ya2sections=False
        if "@" in nom: 
            [nom1,nom2]=nom.split("@")
            ya2sections=True
        
        CodeAppend(self.CodeS,[
        "try:",
        "   print(\"Creation de: "+ V + "\")",
        "   Vd2x=geompy.MakeVectorDXDYDZ("+Vd3xs+")",
        "   Vj3=geompy.MakeVectorDXDYDZ("+vj3rs+")",
        "   Liste=[]",
        "   "+Pn+"= geompy.MakeTranslationVectorDistance("+Px+",Vd2x,"+str(Lc)+")",
        "   Liste.append(["+Pn+",\""+Pn+"\"])",
        "   "+V+"= geompy.MakeVector("+Px+","+Pn+")",
        "   Liste.append(["+V+",\""+V+"\"])",
        ])
        
        if ya2sections:
            CodeAppend(self.CodeS,[
            "   Wire1 = geompy.MakeSketcher(\"Sketcher:"+nom1+"\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   Liste.append([Wire1,\"Wire1\"])",
            "   Wire2 = geompy.MakeSketcher(\"Sketcher:"+nom2+"\",",
            "       [   "+VPx2s+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   Liste.append([Wire2,\"Wire2\"])",
            "   S2D=geompy.MakeThruSections([Wire1,Wire2], theModeSolid=0, thePreci = 0.001, theRuled=1)",
            ])
            
        else:
            CodeAppend(self.CodeS,[
            "   Wire = geompy.MakeSketcher(\"Sketcher:"+nom+"\",",
            "       [   "+VPxs+",",
            "           "+vi3s+",",
            "           "+vj3rs+"]",
            "   )",
            "   S2D=geompy.MakePrism(Wire,"+Px+","+Pn+")",
            ])
        
        if self.iWire2Dsym:
            CodeAppend(self.CodeS,[
            "   plan = geompy.MakePlane2Vec("+V+",Vj3,500)",
            "   Liste.append([plan,\"plan\"])",
            "   S2D2 = geompy.MakeMirrorByPlane(S2D,plan)",    
            "   S2D = geompy.MakeCompound([S2D2,S2D])",
            ])
        
        
        CodeAppend(self.CodeS,[
        "   S2D_id=geompy.addToStudy(S2D,\""+S2D +"\")",
        "   gg.createAndDisplayGO(S2D_id)",
        "   gg.setDisplayMode(S2D_id,1)",

        "   for x in Liste :",
        "       geompy.addToStudyInFather(S2D,x[0],x[1])",

        "except:",
        "   ERREUR=True",
        "   print (\"   =>ERREUR!\")",
        "   for x in Liste :",
        "       geompy.addToStudy(x[0],x[1])",
        
        "try:",
        "   print(\"Maillage de: "+  S2D + "\")",
        "   "+ S2D+"M = smesh.Mesh(S2D)",
        "   Decoupage = "+ S2D+"M.Segment()",
        "   Decoupage.LocalLength("+str(self.LgElement)+",[],1e-07)",
        "   Decoupage.QuadraticMesh()",
        "   Quadrangle_2D = "+ S2D+"M.Quadrangle(algo=smesh.QUADRANGLE)",
        "   Quadrangle_Parameters_1 = Quadrangle_2D.QuadrangleParameters(StdMeshers.QUAD_STANDARD)",
        "   smesh.SetName("+ S2D+"M,'"+S2D+"')",
        "   "+S2D+"M.Compute()",
#        "   "+V+"M.GroupOnGeom("+ Px+")",
#        "   "+V+"M.GroupOnGeom("+Pn+")",
#        "   "+V+"M.GroupOnGeom("+V+")",
        "except:",
        "   ERREUR=True",
        "   print (\"   =>ERREUR!\")",
        ]) 

        
        self.Ajouter_Liaison(lien)

        if self.LastCd not in ["P","Px","Pxvr"]:
            if VerifierColinea(self.Vd2x,Vd3x) == 0 : 
                self.DicP[Pn] =  [[Vd2x,Vd3x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
            else:
                self.DicP[Pn] =  [[Vd1x,Vd2x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press] 
        else:
            self.DicP[Pn] =  [[Vd1x,Vd3x],self.Secx,VPx,V,model,"",self.SIF,self.Temp,self.Press]
            self.DicP[Px] =  [[Vd1x,Vd3x],self.Secx,VPx0,V,model,"",SIFx,self.Temp,self.Press]
    
        self.Px=self.Pn
        self.iWire2Dsym=False

    #---------------------------------------------------------------------------
    def Ajouter_Wire2Ds(self,A,nom,lien):

        self.iWire2Dsym=True
        self.Ajouter_Wire2D(A,nom,lien)


    #---------------------------------------------------------------------------
    def Ajouter_g(self,A,nom,lien): 
        self.Vg=VectNum(A)
        

    #---------------------------------------------------------------------------
    def Conver_Bride(self,A,nom,lien):
        [L,m]=ConvNFloat(A,2)
        Vd2 =  VectRatio(self.Vd2x,L)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd2]])
        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx]
     
    #---------------------------------------------------------------------------
    def Conver_Ca(self,A,nom,lien):
        [rc,ac,ad]=ConvNFloat(A,3)
        [Rc,ec]=self.Secx
        
        if rc<Rc+eps:
            AfficherErreur([  "Ca=rc,a,ad :Le rayon de courbure doi être plus grand que le rayon du tuyau!"])

        self.Vd2x = VectRatio(self.Vd2x,rc) 
        VPc = VectDih(rc,self.Vd1x,self.Vd2x,ad,0)
        VPco = VectOpp(VPc)
        
        Vaxe = ProdVect(VPco,self.Vd2x)
        Vaxe = VectRatio(Vaxe,rc)   
        
        VP1 = RotVect(VPco,Vaxe,ac)
        self.VPx = AddVect([[1,self.VPx],[1,VPc],[1,VP1]])     

        # Calcul des nouveaux Vdx
        Vd3x = VectDih(rc,self.Vd1x,self.Vd2x,ad,ac-90)
        self.Vd1x = self.Vd2x
        self.Vd2x = Vd3x
        
        #print(VectString(self.Vd2x))

        if nom != "":  self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx] 


    #---------------------------------------------------------------------------
    def Conver_Calcul(self,A,nom,lien):
              
        exec("self.X_Conver_Calcul_"+nom+"()")

        self.CodeP.pop(self.iCodeP)
        self.ICodeP-=1
        self.Calcul=nom


    #---------------------------------------------------------------------------
    def X_Conver_Calcul_DYNAMIQUE_PHYSIQUE(self):
        self.iCalc_Dynamique=True
        Lx=TrouverLigne(self.CodeA,"#CALCULS")
        CodeInsert(self.CodeA,Lx,[
        "MACRO_MATR_ASSE(",
        "       MODELE=MODMECA,",
        "       CHAM_MATER=CHMAT,",
        "       CHARGE=BLOCAGE,",
        "       CARA_ELEM=CARAELEM,",
        "       NUME_DDL=CO('NUMEDDL'),",
        "       MATR_ASSE=(",
        "           _F( MATRICE=CO('RIGIDITE'),",
        "               OPTION='RIGI_MECA',",
        "           ),",
        "           _F( MATRICE=CO('MASSE'),",
        "               OPTION='MASS_MECA',",
        "           ),",
        "       ),",
        ");",
        "",
        "#DEF_FONCTION",
        "",
        "LIR=DEFI_LIST_REEL(DEBUT=0.0,",
        "                   INTERVALLE=_F(JUSQU_A=1.0,",
        "                                 PAS=1E-2,),);",
        "",
        "RESU=DYNA_VIBRA(",
        "       TYPE_CALCUL='TRAN',",
        "       BASE_CALCUL='PHYS',",
        "       MATR_MASS=MASSE,",
        "       MATR_RIGI=RIGIDITE,",
        "       SCHEMA_TEMPS=_F(SCHEMA='NEWMARK',),",
        "       EXCIT=(",
        "       #DEF_FONC_MULT",
        "       ),"
        "       INCREMENT=_F(LIST_INST=LIR,),);",
        "",
        "IMPR_RESU(FORMAT='MED',RESU=_F(RESULTAT=RESU));",
        ])

  
        
    #---------------------------------------------------------------------------
    def X_Conver_Calcul_MODES_PROPRES(self):
        Lx=TrouverLigne(self.CodeA,"#CALCULS")
        CodeInsert(self.CodeA,Lx,[
        "MACRO_MATR_ASSE(",
        "       MODELE=MODMECA,",
        "       CHAM_MATER=CHMAT,",
        "       CHARGE=BLOCAGE,",
        "       CARA_ELEM=CARAELEM,",
        "       NUME_DDL=CO('NUMEDDL'),",
        "       MATR_ASSE=(",
        "           _F( MATRICE=CO('RIGIDITE'),",
        "               OPTION='RIGI_MECA',",
        "           ),",
        "           _F( MATRICE=CO('MASSE'),",
        "               OPTION='MASS_MECA',",
        "           ),",
        "       ),",
        ");",
        "",
        "MODES=MODE_ITER_SIMULT(",
        "       MATR_A=RIGIDITE,",
        "       MATR_B=MASSE,",
        "       METHODE='SORENSEN',",
        "       CALC_FREQ=_F(   OPTION='BANDE',",
        "                       FREQ=(0.0,"+str(self.freqMax)+",),",
        "                       ),"
        "       TITRE='METHODE DE SORENSEN',",
        ");", 
        "",        
        "MODES=NORM_MODE(reuse=MODES,MODE=MODES,NORME='EUCL',);",
        "",
        "IMPR_RESU(RESU=_F(RESULTAT=MODES,TOUT_PARA= 'OUI',TOUT_CHAM= 'NON'),);",   
        "",                                              
        "IMPR_RESU(",
        "     MODELE=MODMECA,",
        "     FORMAT='MED',",
        "     RESU=(",  
        "           _F( MAILLAGE=MAIL,",
        "               RESULTAT=MODES,",
        "            ),",                                     
        "     )",
        ");",
        ])     
   
    #---------------------------------------------------------------------------
    def X_Conver_Calcul_ANALYSE_SISMIQUE(self):
        Lx=TrouverLigne(self.CodeA,"#CALCULS")
        CodeInsert(self.CodeA,Lx,[
        "MACRO_MATR_ASSE(",
        "                       MODELE=MODMECA,",
        "                       CHAM_MATER=CHMAT,",
        "                       CHARGE=BLOCAGE,",
        "                       CARA_ELEM=CARAELEM,",
        "                       NUME_DDL=CO('NUMEDDL'),",
        "                       MATR_ASSE=(",
        "                           _F(     MATRICE=CO('RIGIDITE'),",
        "                                   OPTION='RIGI_MECA',",
        "                                   ),",
        "                           _F(     MATRICE=CO('MASSE'),",
        "                                   OPTION='MASS_MECA',",
        "                                   ),",
        "                           ),",
        "                       );",
        "",

        "MAS=POST_ELEM(",
        "                       MODELE=MODMECA,",
        "                       CHAM_MATER=CHMAT,",
        "                       CARA_ELEM=CARAELEM,",
        "                       MASS_INER=_F(  TOUT = 'OUI')",
        "                       ),"
        "",
        
        "MODES=MODE_ITER_SIMULT(",
        "                       MATR_A=RIGIDITE,",
        "                       MATR_B=MASSE,",
        "                       METHODE='SORENSEN',",
        "                       CALC_FREQ=_F(   OPTION='BANDE',",
        "                                       FREQ=(0.0,"+str(self.freqMax)+",),",
        "                                   ),"
        "                       TITRE='METHODE DE SORENSEN',",
        "                       );", 
        "",
        "MODES=NORM_MODE(reuse=MODES,   MODE=MODES,   NORME='TRAN_ROTA',)",
        "",
        "#",
        "# DEFINITION DU SPECTRE:",
        "#-----------------------",
        "",
        "ACCE_XY=DEFI_FONCTION(  NOM_PARA='FREQ',    ",
        "                        INTERPOL='LOG',",
        "                        VALE=( ",
        "                                1.0,    1.962,",
        "                                10.0,   19.62,",
        "                                30.0,   19.62,",
        "                                100.0,  1.962,",
        "                                10000.0,1.962,          ",
        "                                )       ",
        "                        )",
        "",
        "ACCE_Z=DEFI_FONCTION(   NOM_PARA='FREQ',    ",
        "                        INTERPOL='LOG',",
        "                        VALE=(  ",
        "                                1.0,    0.981,   ",
        "                                10.0,   9.81,",
        "                                30.0,   9.81,   ",
        "                                100.0,    0.981,",
        "                                10000.0,   0.981,          ",
        "                                )       ",
        "                          )",
        "",
        "SPECT_XY=DEFI_NAPPE(   NOM_PARA='AMOR',",
        "                       INTERPOL=( 'LIN', 'LOG', ),",
        "                       PARA=(     0.02,     0.05,     ),",
        "                       FONCTION=( ACCE_XY,  ACCE_XY,  )  ",
        "                       )",
        "",
        "SPECT_Z=DEFI_NAPPE(    NOM_PARA='AMOR',    ",
        "                       INTERPOL='LOG',",
        "                       PARA=(     0.02,     0.05,   ),",
        "                       FONCTION=( ACCE_Z,   ACCE_Z, )  ",
        "                       )",
        "MODE_ST1=MODE_STATIQUE(MATR_RIGI=RIGIDITE,",
        "                       MATR_MASS=MASSE,",
        "                       PSEUDO_MODE=(",
        "#DIR_PSEUDO_MODE",
        "                                   ),",
        "                       )",
        "",
        "MODE_STA=MODE_STATIQUE(MATR_RIGI=RIGIDITE,",    
        "                       MATR_MASS=MASSE,",
        "                       MODE_STAT=_F(   TOUT = 'OUI',",
        "                                       TOUT_CMP = 'OUI'  ",
        "                                       )",
        "                       );",
        "",
        "SISM_MU2=COMB_SISM_MODAL(  ",
        "                        MODE_MECA=MODES,",
        "                        AMOR_REDUIT=0.03,",
        "                        MASS_INER=MAS,",
        "                        CORR_FREQ='NON',",
        "                        MODE_CORR=MODE_ST1,",
        "                        MULTI_APPUI ='CORRELE',",
        "                        EXCIT=(",
        "#SPECTRE_NOEUD",
        "                            ),",
        "                        COMB_MULT_APPUI=(",
        "                            _F(     TOUT='OUI',",
        "                                    TYPE_COMBI = 'LINE'),",
        "                             ),",
#        "                        DEPL_MULT_APPUI=(",
#        "                             _F(    NUME_CAS = 1,",
#        "                                    NOM_CAS ='DEPL EN N_ENCASTRE',",
#        "                                    MODE_STAT = MODE_STA,",
#        "                                    NOEUD_REFE = 'ENCASTRE',",
#        "                                    GROUP_NO = 'ENCASTRE',",
#        "                                    DX = 0.),",
#        "                            _F(     NUME_CAS = 2,",
#        "                                    NOM_CAS ='DEPL EN N5 ET N9',",
#        "                                    MODE_STAT = MODE_STA,",
#        "                                    NOEUD = ( 'N5',  'N9', ),",
#        "                                    DX = 0.001)",
#        "                       ),",
        "",
        "                        COMB_MODE=_F(  TYPE = 'CQC'),",
        "",
        "                        COMB_DIRECTION=_F(  TYPE = 'QUAD'),",
        "",
        "                        OPTION=( 'DEPL',  'REAC_NODA', )",
        "                       )",
        "IMPR_RESU(FORMAT='MED',RESU=_F(RESULTAT=SISM_MU2));",
        ])
           
   
   
   
   
    #---------------------------------------------------------------------------
    def X_Conver_Calcul_STATIQUE_LINEAIRE(self):  
    
    
        LTex=[  
        "RESU=MECA_STATIQUE(",
        "     MODELE=MODMECA,",
        "     CHAM_MATER=CHMAT,",
        "     CARA_ELEM=CARAELEM,",
        "     INST=1,",
        "     EXCIT=(",
        "         _F(   CHARGE=BLOCAGE",
        "          ),",
        "         _F(   CHARGE=POIDS,",
        "          ),",
        "         _F(   CHARGE=CHARG1,",
        "          ),",
        
        "         #CHARGEMENT",
        "     ),",
        ");",
        "",  
        "IMPR_RESU(FORMAT='MED',RESU=_F(RESULTAT=RESU));",  
        ]
        Lx=TrouverLigne(self.CodeA,"#CALCULS")
        CodeInsert(self.CodeA,Lx,LTex)   
  
    #---------------------------------------------------------------------------
    def X_Conver_Calcul_STATIQUE_LINEAIRE_CHARPENTE(self):  
    
    
        LTex=[  
        "RESU=MECA_STATIQUE(",
        "     MODELE=MODMECA,",
        "     CHAM_MATER=CHMAT,",
        "     CARA_ELEM=CARAELEM,",
        "     INST=1,",
        "     EXCIT=(",
        "         _F(   CHARGE=BLOCAGE",
        "          ),",
        "         _F(   CHARGE=POIDS,",
        "          ),",
        "         _F(   CHARGE=CHARG1,",
        "          ),",
        
        "         #CHARGEMENT",
        "     ),",
        ");",
        "",  
        "IMPR_RESU(FORMAT='MED',RESU=_F(RESULTAT=RESU));",  
        ]
        Lx=TrouverLigne(self.CodeA,"#CALCULS")
        CodeInsert(self.CodeA,Lx,LTex) 
        
  
        
        
    #---------------------------------------------------------------------------
    def X_Conver_Calcul_STATIQUE_LINEAIRE_FLEXIBILITE(self):  
    
        self.iCalc_Flex=True
    
        LTex=[
        "#-------------------------------------------------------------------------------",
        "# Champ de pression",
        "#-------------------------------------------------------------------------------",
        "CHA_PRES=CREA_CHAMP(",
        "     OPERATION='AFFE',",
        "     TYPE_CHAM='NOEU_TEMP_R',",
        "     MODELE=MODMECA,",
        "     AFFE=(",
        "            _F( TOUT='OUI',",
        "                NOM_CMP='TEMP',",
        "                VALE=0,",
        "                ),",
        "",
        "                #CHAMP_PRESS",
        "    ),",
        ");",
        "IMPR_RESU(FORMAT='MED',RESU=_F(CHAM_GD=CHA_PRES));",
        "",
        "#-------------------------------------------------------------------------------",
        "# Contraintes liées à la pression",
        "#-------------------------------------------------------------------------------",
        "CHA_SIGP=CREA_CHAMP(",
        "     OPERATION='AFFE',",
        "     TYPE_CHAM='NOEU_TEMP_R',",
        "     MODELE=MODMECA,",
        "     AFFE=(",
        "            _F( TOUT='OUI',",
        "                NOM_CMP='TEMP',",
        "                VALE=0,",
        "                ),",
        "",
        "                #CHAMP_SIGP",
        "    ),",
        ");",
        "",
        "IMPR_RESU(FORMAT='MED',RESU=_F(CHAM_GD=CHA_SIGP));",
        "",
        "#-------------------------------------------------------------------------------",
        "# Champ de SIF",
        "#-------------------------------------------------------------------------------",
        "CHA_SIF=CREA_CHAMP(",
        "     OPERATION='AFFE',",
        "     TYPE_CHAM='NOEU_TEMP_R',",
        "     MODELE=MODMECA,",
        "     AFFE=(",
        "            _F( TOUT='OUI',",
        "                NOM_CMP='TEMP',",
        "                VALE=1,",
        "                ),",
        "                ",
        "",
        "                #CHAMP_SIF",
        "    ),",
        ");",
        "",
        "IMPR_RESU(FORMAT='MED',RESU=_F(CHAM_GD=CHA_SIF));",
        "#CREA_CHAMP",
        "",
        "                 ",
        "",
        "#CREA_CHAMP",
        "",
        ]   
        Lx=TrouverLigne(self.CodeA,"#CHAMPS_FLEX")
        CodeInsert(self.CodeA,Lx,LTex)
    
    
        LTex=[  
        "RES_PP=MECA_STATIQUE(",
        "     MODELE=MODMECA,",
        "     CHAM_MATER=CHMAT,",
        "     CARA_ELEM=CARAELEM,",
        "     INST=1,",
        "     EXCIT=(",
        "         _F(",
        "             CHARGE=BLOCAGE",
        "         ),",
        "         _F(",
        "             CHARGE=POIDS,",
        "         ),",
        "         #CHARGEMENT",
        "     ),",
        ");",
        "",          
        "RES_PP=CALC_CHAMP(reuse =RES_PP,",
        "     RESULTAT=RES_PP,",
        "     CONTRAINTE=('SIPO_NOEU','SIEF_NOEU'),",
        "     FORCE=('REAC_NODA','FORC_NODA')",
        ");",
        "MFlex = FORMULE(",
        "       NOM_PARA=('SMFY', 'SMFZ', ),",
        "       VALE=\"\"\"sqrt(SMFY**2 + SMFZ**2 )\"\"\"",
        ")",
        "",
        "RES_MPP = CALC_CHAMP(",
        "       RESULTAT=RES_PP,",
        "       CHAM_UTIL=_F(",
        "           NOM_CHAM='SIPO_NOEU',",
        "           FORMULE=(MFlex),",
        "           NUME_CHAM_RESU=2,",
        "       ),",
        ");",
        
        "CHA_MPP = CREA_CHAMP(",
        "       TYPE_CHAM='NOEU_NEUT_R',",
        "       RESULTAT=RES_MPP,",
        "       OPERATION='EXTR',",
        "       NOM_CHAM='UT02_NOEU',",
        ");",
        
        "CHX_MPP=CREA_CHAMP (",
        "       OPERATION='ASSE', ",
        "       TYPE_CHAM='NOEU_NEUT_R',",
        "       MAILLAGE=MAIL,",
        "       ASSE=_F (   TOUT = 'OUI', ",
        "                   CHAM_GD = CHA_MPP,",
        "                   NOM_CMP = ('X1'), ",
        "                   NOM_CMP_RESU = ('X2'),",
        "       ),",
        ");",
        "",   
        
        "CHX_SIF=CREA_CHAMP (",
        "    OPERATION='ASSE', ",
        "    TYPE_CHAM='NOEU_NEUT_R', ",
        "    MAILLAGE=MAIL,",
        "    ASSE=_F (   TOUT = 'OUI',", 
        "                CHAM_GD = CHA_SIF,",
        "                NOM_CMP = ('TEMP',),", 
        "                NOM_CMP_RESU = ('X1',),",
        "    ),",
        ");",
        "", 

        "def HEAVYS(x) :",
        "       if x<=1. : return 1.",
        "       if x>1. : return x",
        "",

        "F_HV = FORMULE(",
        "       NOM_PARA = 'X1',",
        "       VALE = 'HEAVYS(X1*0.75)',",
        ");",
        "",
        
        
        "CHFHVS=CREA_CHAMP(",
        "       OPERATION='AFFE',",
        "       TYPE_CHAM='NOEU_NEUT_F',",
        "       MAILLAGE=MAIL,",
        "       AFFE=_F (",
        "           TOUT = 'OUI', ",
        "           NOM_CMP = 'X4',",
        "           VALE_F = F_HV,",
        "       ),",
        ");",
        "",

        
        "CHX_iM_S=CREA_CHAMP (",
        "       OPERATION='EVAL',",
        "       TYPE_CHAM='NOEU_NEUT_R',",
        "       CHAM_F=CHFHVS,",
        "       CHAM_PARA= (CHX_SIF),",
        ");",
        "",

           
        "FMULT1 = FORMULE(",
        "       NOM_PARA = ('X4', 'X2'),",
        "       VALE = 'X4*X2',",
        ");",
        "",
        
        
        "CHFMU1=CREA_CHAMP(",
        "       OPERATION='AFFE',",
        "       TYPE_CHAM='NOEU_NEUT_F',",
        "       MAILLAGE=MAIL,",
        "       AFFE=_F (",
        "           TOUT = 'OUI', ",
        "           NOM_CMP = 'X3',",
        "           VALE_F = FMULT1,",
        "       ),",
        ");",
        "",


        
        "CHX_iM=CREA_CHAMP (",
        "       OPERATION='EVAL',",
        "       TYPE_CHAM='NOEU_NEUT_R',",
        "       CHAM_F=CHFMU1,",
        "       CHAM_PARA= (CHX_iM_S, CHX_MPP),",
        ");",
        "",
        
        
        "CHA_iM=CREA_CHAMP (",
        "       OPERATION='ASSE',",
        "       TYPE_CHAM='NOEU_TEMP_R',",
        "       MAILLAGE=MAIL,",
        "       ASSE=_F (",
        "           TOUT = 'OUI',",
        "           CHAM_GD = CHX_iM,",
        "           NOM_CMP = ('X3',),",
        "           NOM_CMP_RESU = ('TEMP',),",
        "       ),",
        ");",
        "",
        
        
        "CHA_1= CREA_CHAMP (",
        "       OPERATION='COMB',",
        "       TYPE_CHAM='NOEU_TEMP_R',",
        "       COMB= (",
        "               _F (CHAM_GD=CHA_SIGP, COEF_R= 1.),",
        "               _F (CHAM_GD=CHA_iM, COEF_R=1),",
        "       ),",
        ");",
        "",


        "IMPR_RESU(FORMAT='MED',RESU=_F(CHAM_GD=CHA_1));",     
        "#IMPR_RESU(FORMAT='MED',RESU=_F(CHAM_GD=CHX_iM_S));",     
        "",
        "IMPR_RESU(",
        "            FORMAT='MED',",
        "            RESU=_F(",
        "                MAILLAGE=MAIL,",
        "                RESULTAT=RES_PP,",
        "            ),",
        "       );",
        "",
        
        
        "#----------------------------------------------------------",
           
        "RES_TH=MECA_STATIQUE(",
        "     MODELE=MODMECA,",
        "     CHAM_MATER=CHMATH,",
        "     CARA_ELEM=CARAELEM,",
        "     INST=1,",
        "     EXCIT=(",
        "         _F(",
        "             CHARGE=BLOCAGE,",
        "         ),",
        "         #CHARGEMENT",
        "     ),",
        ");",
        "",
        
        
        "RES_TH=CALC_CHAMP(reuse =RES_TH,",
        "     RESULTAT=RES_TH,",
        "     CONTRAINTE=('SIPO_NOEU'),",
        "     FORCE=('REAC_NODA',)",
        ");",
        "",
        
        
        "RES_MTH = CALC_CHAMP(",
        "       RESULTAT=RES_PP,",
        "       CHAM_UTIL=_F(",
        "           NOM_CHAM='SIPO_NOEU',",
        "           FORMULE=(MFlex),",
        "           NUME_CHAM_RESU=2,",
        "       ),",
        ");",
        
        
        "CHA_MTH = CREA_CHAMP(",
        "       TYPE_CHAM='NOEU_NEUT_R',",
        "       RESULTAT=RES_MTH,",
        "       OPERATION='EXTR',",
        "       NOM_CHAM='UT02_NOEU',",
        ");",
        
        
        "CHX_MTH=CREA_CHAMP (",
        "       OPERATION='ASSE', ",
        "       TYPE_CHAM='NOEU_NEUT_R',",
        "       MODELE=MODMECA,",
        "       ASSE=_F (   TOUT = 'OUI', ",
        "                   CHAM_GD = CHA_MTH,",
        "                   NOM_CMP = ('X1'), ",
        "                   NOM_CMP_RESU = ('X2'),",
        "       ),",
        ");",
        "",   
        
        "FMULT4 = FORMULE(",
        "       NOM_PARA = ('X1', 'X2'),",
        "       VALE = 'X1*X2',",
        ");",
        "",
        
        
        "CHFMU4=CREA_CHAMP(",
        "       OPERATION='AFFE',",
        "       TYPE_CHAM='NOEU_NEUT_F',",
        "       MAILLAGE=MAIL,",
        "       AFFE=_F (",
        "           TOUT = 'OUI', ",
        "           NOM_CMP = 'X3',",
        "           VALE_F = FMULT4,",
        "       ),",
        ");",
        "",

        
        "CHX_iMTH=CREA_CHAMP (",
        "       OPERATION='EVAL',",
        "       TYPE_CHAM='NOEU_NEUT_R',",
        "       CHAM_F=CHFMU4,",
        "       CHAM_PARA= (CHX_SIF, CHX_MTH),",
        ");",
        "",
        
        
        "CHA_iMTH=CREA_CHAMP (",
        "       OPERATION='ASSE',",
        "       TYPE_CHAM='NOEU_TEMP_R',",
        "       MAILLAGE=MAIL,",
        "       ASSE=_F (",
        "           TOUT = 'OUI',",
        "           CHAM_GD = CHX_iMTH,",
        "           NOM_CMP = ('X3',),",
        "           NOM_CMP_RESU = ('TEMP',),",
        "       ),",
        ");",
        "",
        
        
        "CHA_4= CREA_CHAMP (",
        "       OPERATION='COMB',",
        "       TYPE_CHAM='NOEU_TEMP_R',",
        "       COMB= (",
        "               _F (CHAM_GD=CHA_iMTH, COEF_R= 1.),",
        "               _F (CHAM_GD=CHA_1, COEF_R=1.),",
        "       ),",
        ");",
        "",

        "IMPR_RESU(FORMAT='MED',RESU=_F(CHAM_GD=CHA_4));",     
        "",
        
        "IMPR_RESU(",
        "     FORMAT='MED',",
        "     RESU=_F(",
        "         MAILLAGE=MAIL,",
        "         RESULTAT=RES_TH,",
        "     ),",
        ");",
        
        ]
        Lx=TrouverLigne(self.CodeA,"#CALCULS")
        CodeInsert(self.CodeA,Lx,LTex)
            
            
            
            
    #---------------------------------------------------------------------------
    def X_Conver_Calcul_STATIQUE_NON_LINEAIRE(self):
        Lx=TrouverLigne(self.CodeA,"#CALCULS")
        CodeInsert(self.CodeA,Lx,[  
        "L_INST=DEFI_LIST_REEL(",
        "   DEBUT=0,",
        "   INTERVALLE=_F(",
        "   JUSQU_A = 1,",
        "         NOMBRE = 1,",
        "         #STN_NOMBRE",
        "     ),",
        ");",
        "",
        "#RAMPE",
        "",
        "RESU=STAT_NON_LINE(",
        "   MODELE=MODMECA,",
        "   CHAM_MATER=CHMAT,",
        "   CARA_ELEM=CARAELEM,",
        "   EXCIT=(",
        "         _F(",
        "             CHARGE = BLOCAGE",
        "         #F_BLOC1,",
        "         ),",
        "         _F(",
        "             CHARGE = POIDS,",
        "         #F_POIDS,",
        "         ),",
        "         _F(",
        "             CHARGE = CHARG1,",
        "         #F_CHARG1",
        "         ##STN:RAMPE",
        "         ),", 
        "         _F(",
        "             CHARGE = CHARG2,",
        "         #F_CHARG2,",
        "         ),",
        "         #CHARGEMENT",
        "       ),",
        "   INCREMENT=_F(",
        "       LIST_INST = L_INST,",
        "   ),",
        "   COMP_ELAS=(",
        "         #COMP_ELAS_CABLE",  
        "   ),",
        "   COMP_INCR=_F(",
        "       RELATION='ELAS',",
        "       ),",
        "   CONVERGENCE=_F(",
        "         RESI_GLOB_RELA = 1.00E-07,",
        "         ITER_GLOB_MAXI = 1000,",
        "   ),",
        "   NEWTON=_F(",
        "         REAC_ITER = 1",
        "   )",
        ");",

        
        "IMPR_RESU(",
        "     FORMAT='MED',",
        "     UNITE=80,",
        "     RESU=_F(",
        "          MAILLAGE=MAIL,",
        "          RESULTAT=RESU,",
        "     ),",
        ");",
        ])
        
    
    
        
    #---------------------------------------------------------------------------------------------------------------
    def Conver_Ci(self,A,nom,lien):

        [Rc,ec]=self.Secx
        if A!=[]:Rc = float(A[0])

        # Modification des commandes APRES Ci
        v1=self.CodeP[self.iCodeP+1]
        [Cd1,A1,nom1,lien]=Fractionner(v1)
        
        if Cd1 == "V":
            Vdx = VectNum(A1)
        else:
            AfficherErreur(["Il faut un V après le Ci"])

        [vd2x,vd3x,vd4x] = BaseDih(self.Vd1x,self.Vd2x)     
        ad = AngleVect(vd4x,Vdx,vd2x)  
        vd4xd = RotVect(vd4x,vd2x,ad)      
        vd3xd = RotVect(vd3x,vd2x,ad)  
        bd = AngleVect(vd4xd,Vdx,vd3xd)


        if bd > 90 : bd = -180+bd
          
        if bd < -90 : bd = 180+bd
       
        if bd > 88 :
           AfficherErreur([" Angle très ouvert!"])
                
        if bd < -88 :
           AfficherErreur([" Angle très serré!"])                    

        LV = NormVect(Vdx)

        if 90 - abs(bd) < 5.0:
            AfficherErreur([" Erreur: Angle trop fermé ou trop ouvert"])
            
        ac = 90-bd
        acr = ac * math.pi /180    
        d=abs(Rc*math.tan(acr/2) )
        if LV-d < 0 : AfficherErreur(["Configuration impossible avec ce rayon de courbure"])
        Vdxi=VectRatio(Vdx,LV-d)
        Vdxis=VectString2(Vdxi)
        tex="V="+Vdxis
        if nom1!="":tex+=":"+nom1
        self.CodeP[self.iCodeP+1]=tex
        vdx = VectRatio(Vdx,d)         
        self.VPx = AddPVect(self.VPx,vdx)         
          
        self.Vd1x = self.Vd2x[:]
        self.Vd2x = Vdx[:]
              
              
                 
        # Modification des commandes AVANT Ci       
        v1=self.CodeP[self.iCodeP-1]
        [Cd1,A1,nom1,lien]=Fractionner(v1)

        
        if Cd1 == "V":
            V1 = VectNum(A1)
            LV1=NormVect(V1)
            if LV1-d < 0 : AfficherErreur(["Configuration impossible avec ce rayon de courbure"])
            Vp = VectRatio(V1,LV1-d)
            Vps = VectString2(Vp)
            tex="V="+Vps
            if nom1 != "":
                tex += ":"+nom1
            self.CodeP[self.iCodeP-1]=tex
        else:
            AfficherErreur(["Il faut un V avant le Ci"])
            
        if nom=="":
            tex="Ca="+ str(Rc) + "," + str(ac) + "," + str(ad)
            self.CodeP[self.iCodeP]=tex
        else:
            self.CodeP.pop(self.iCodeP)
            L=[
            "Ca="+ str(Rc) + "," + str(ac/2) + "," + str(ad)+":"+nom,
            "Ca="+ str(Rc) + "," + str(ac/2) + "," + str(0)
            ]
            CodeInsert(self.CodeP,self.iCodeP,L)
            self.iCodeP+=1
            self.ICodeP+=1

    #---------------------------------------------------------------------------------------------------------------
    def Conver_CouleA(self,A,nom,lien):
        
        [ad1,ad2,ad3,Rp,ep,Ld,Le,Lh,dL,rc]=ConvNFloat(A,8)   
        [Rc,ec]=self.Secx
        self.CodeP.pop(self.iCodeP)   
        alpha = math.atan(Le/Ld)*180/math.pi
        vLd=Ld-Kpiq_p*Rc-rc
        Ltex=[
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad2)+"3,0 : "+nom+"_BE",
        "Vc="+str(dL/2),
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad1)+"3,0 : "+nom+"_E",
        "Vc="+str(dL/2),
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad2+alpha)+"3,0:"+nom+"_BS",
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad3)+"3,0:"+nom+"_S",
        "Vc="+str(dL)+":"+nom+"_M",
        "Pxvr:"+nom+"_BE",
        "Vc="+str(vLd),
        "Ca="+str(rc)+",90,180",
        "Vc="+str(Lh-2*rc),
        "Ca="+str(rc)+",90,-90",
        "Vc="+str(Le-2*rc),
        "Ca="+str(rc)+",90,0",
        "Vc="+str(Lh-dL-2*rc),  
        "Ca="+str(rc)+",90,"+str(90-alpha),
        "VPx:"+nom+"_BS",
        "Pxvr:"+nom+"_M",
        ]
        CodeInsertListe(self.CodeP,self.iCodeP,Ltex)
        self.ICodeP += len(Ltex)-1
        self.iCodeP -=1
       	    
    #---------------------------------------------------------------------------------------------------------------
    def Conver_CouleB(self,A,nom,lien):
        
        [ad1,ad2,ad3,Rp,ep,Ld,Le,Lh,dL,rc]=ConvNFloat(A,8)   
        [Rc,ec]=self.Secx
        self.CodeP.pop(self.iCodeP)   
        alpha = math.atan(Le/Ld)*180/math.pi
        vLd=Ld-Kpiq_p*Rc-rc
        Ltex=[
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad2-alpha)+"3,0 : "+nom+"_BS",
        "Vc="+str(dL/2),
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad1)+"3,0 : "+nom+"_S",
        "Vc="+str(dL/2),
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad2)+"3,0:"+nom+"_BE",
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad3)+"3,0:"+nom+"_E",
        "Vc="+str(dL)+":"+nom+"_M",
        "Pxvr:"+nom+"_BE",
        "Vc="+str(vLd),
        "Ca="+str(rc)+",90,180",
        "Vc="+str(Lh-dL-2*rc),
        "Ca="+str(rc)+",90,90",
        "Vc="+str(Le-2*rc),
        "Ca="+str(rc)+",90,0",
        "Vc="+str(Lh-2*rc),  
        "Ca="+str(rc)+",90,"+str(alpha-90),
        "VPx:"+nom+"_BS",
        "Pxvr:"+nom+"_M",
        ]
        CodeInsertListe(self.CodeP,self.iCodeP,Ltex)
        self.ICodeP += len(Ltex)-1
        self.iCodeP -=1
        
    #---------------------------------------------------------------------------
    def Conver_CouleC(self,A,nom,lien):
        
        [ad1,ad2,ad3,Rp,ep,Ld,Le,Lh,dL,rc]=ConvNFloat(A,8)   
        [Rc,ec]=self.Secx
        self.CodeP.pop(self.iCodeP)   
        alpha = math.acos(Ld/Le)*180/math.pi
        vLd=Ld-Kpiq_p*Rc-rc
        Ltex=[
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad2)+"3,0 : "+nom+"_BE",
        "Vc="+str(dL/2),
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad1)+"3,0 : "+nom+"_E",
        "Vc="+str(dL/2),
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad2-90)+"3,0:"+nom+"_BS",
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad3)+"3,0:"+nom+"_S",
        "Vc="+str(dL)+":"+nom+"_M",
        "Pxvr:"+nom+"_BE",
        "Vc="+str(vLd),
        "Ca="+str(rc)+",90,180",
        "Vc="+str(Lh-2*rc),
        "Ca="+str(rc)+",90,"+str(alpha),
        "Vc="+str(Le-2*rc),
        "Ca="+str(rc)+",90,0",
        "Vc="+str(Lh-dL-2*rc),  
        "Ca="+str(rc)+",90,"+str(alpha-90),
        "VPx:"+nom+"_BS",
        "Pxvr:"+nom+"_M",
        ]
        CodeInsertListe(self.CodeP,self.iCodeP,Ltex)
        self.ICodeP += len(Ltex)-1
        self.iCodeP -=1
        
    #---------------------------------------------------------------------------
    def Conver_Face(self,A,nom,lien):
        self.Conver_Wire(A,nom,lien)


    #---------------------------------------------------------------------------------------------------------------
    def Conver_Hc(self,A,nom,lien):
        
        [r,h,n]=ConvNFloat(A,3)
            
        #Nombre de parties pour un tour
        N0=5
        hb=h/2/math.pi
        c= pow(r*r+hb*hb,0.5)
        Rc=c*c/r 
        dt=1/N0
        ac=360*r*dt/c 
        ad=360*hb*dt/c 
        
        N=int(N0*n)
        self.CodeP.pop(self.iCodeP)
        L=[]
        for i in range(0,N-1):
            L.append("Ca= "+str(Rc)+","+str(ac)+","+str(ad))
        
        if nom=="":
            L.append("Ca= "+str(Rc)+","+str(ac)+","+str(ad))
        else:
            L.append("Ca= "+str(Rc)+","+str(ac)+","+str(ad)+":"+nom)
        
        CodeInsertListe(self.CodeP,self.iCodeP,L)
        self.ICodeP += (N-1)
        self.iCodeP += N    
        

    #---------------------------------------------------------------------------------------------------------------
    def Conver_Lyre(self,A,nom,lien):
        	    
        [L,Ly,dL,rc,ad]=ConvNFloat(A,4)       
        self.CodeP.pop(self.iCodeP) 
        L1=(L-dL)/2
        LTex=[
        "Vc=" + str(L1),
        "Ci= "+str(rc),
        "Vd= "+str(Ly)+","+str(ad)+",0",
        "Ci= "+str(rc),
        "Vd= "+str(dL/2)+",180,0:"+nom,
        "Vc= "+str(dL/2),
        "Ci= "+str(rc),
        "Vd= "+str(Ly)+",0,0",
        "Ci= "+str(rc),
        "Vd= "+str(L1)+",180,0",
        ]
        
        CodeInsert(self.CodeP,self.iCodeP,LTex)
        
        self.ICodeP += len(LTex) - 2
        self.iCodeP -=1
        
    #---------------------------------------------------------------------------
    def Conver_Mat(self,A,nom,lien):
        self.matx = nom

    #---------------------------------------------------------------------------
    def Conver_Model(self,A,nom,lien):
        self.model = nom


    #---------------------------------------------------------------------------
    def Conver_NP(self,A,nom,lien):

        [N,L,ad,u]=ConvNFloat(A,4)
        N = int(N)
        if abs(u-0)<eps : u=360/N
        
        self.CodeP.pop(self.iCodeP) 
          
        for k in range(0,N):      
            CodeInsertListe(self.CodeP,self.iCodeP,[
            "Pd = "+str(L)+","+str(ad)+"+"+str(u)+"*"+str(k)+",0:"+nom+str(k),
            "Px :"+nom,
            ])     
        self.ICodeP += 2*N
        self.iCodeP -=1
        
    #---------------------------------------------------------------------------
    def Conver_P(self,A,nom,lien):
        self.VPx = VectNum(A)
        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]     
        

    #---------------------------------------------------------------------------------------------------------------
    def Conver_Pc(self,A,nom,lien) :
        
        L=float(A[0])
        Vd2=VectRatio(self.Vd2x,L)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd2]])  

        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]   

    #---------------------------------------------------------------------------------------------------------------
    def Conver_Pd(self,A,nom,lien) :

        [L,ad,bd]=ConvNFloat(A,3)    
        Vd3x =  VectDih(L,self.Vd1x,self.Vd2x,ad,bd)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd3x]])
        
        VPxs=VectString2(self.VPx)
        tex="P = "+VPxs
        if nom!="":tex+=":"+nom
        self.CodeP[self.iCodeP]=tex

        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]   

        self.Vd1x = self.Vd2x
        self.Vd2x = Vd3x
        
    #----------------------------------------------------------------------    
    def Conver_Piq(self,A,nom,lien):

        [Rp,ep,ad,bd,rc,n] =  ConvNFloat(A,6)
        SecPiq = [Rp,ep]
        [Rc,ec]=self.Secx

        Lc0 = Kpiq_c*Rp
        Lp0 = Kpiq_p*Rp
        
        VPn =  VectRatio(self.Vd2x,Lc0)

        Vd3mp =  VectDih(Lp0,self.Vd1x,self.Vd2x,ad,bd)

        VPp =  AddVect([[1,self.VPx],[1,Vd3mp]]) 
        self.VPx =  AddVect([[1,self.VPx],[1,VPn]]) 

        self.DicP[nom] = [[self.Vd2x,Vd3mp],SecPiq,VPp,"","",""]  

        if self.conver==2:
            i=1
            while True:
                v1=self.CodeP[self.iCodeP-i]
                [Cd1,A1,nom1,lien]=Fractionner(v1)
                if Cd1=="V" :
                    break
                else:
                    i+=1
            V=VectNum(A1)  
            LV=NormVect(V)
            if LV<Lc0: AfficherErreur(["Longueur insuffisante avant Piq"])
            V=VectRatio(V,LV-Lc0)
            Vs=VectString2(V)
            tex="V="+Vs
            if nom1 != "": tex += ":"+nom1
            self.CodeP[self.iCodeP-i]=tex
            
            i=1
            while True:
                v1=self.CodeP[self.iCodeP+i]
                [Cd1,A1,nom1,lien]=Fractionner(v1)
                if Cd1=="V" :
                    break
                else:
                    i+=1
            V=VectNum(A1)  
            LV=NormVect(V)
            if LV<Lc0: AfficherErreur(["Longueur insuffisante après Piq"])
            V=VectRatio(V,LV-Lc0)
            Vs=VectString2(V)
            tex="V="+Vs
            if nom1 != "": tex += ":"+nom1
            self.CodeP[self.iCodeP+i]=tex


    #---------------------------------------------------------------------------------------------------------------
    def Conver_Pn(self,A,nom,lien) :

        self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]

    #---------------------------------------------------------------------------------------------------------------      
    def Conver_PcPxK(self,A,nom,lien):

        k=float(A[0])
        nomx=""
        if "," in nom:[nom,nomx]=nom.split(",")
        [Vdx1,Secx1,VPx1,nom1,model1,sec1] = self.DicP[nom] 
        Vdx = Vect(self.VPx,VPx1)
        LVdx=NormVect(Vdx)
        LV=LVdx/k
        Vdxc=VectRatio(Vdx,LV)
        self.VPx=AddPVect(self.VPx,Vdxc)
        VPxs=VectString2(self.VPx)
        tex="P="+VPxs
        if nomx!="":tex+=":"+nomx
        self.CodeP[self.iCodeP]=tex  

        if nomx != "": self.DicP[nomx] = [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]        

    #---------------------------------------------------------------------------------------------------------------
    def Conver_Px(self,A,nom,lien):
        
        [Vdx,Sec,self.VPx,noma,modela,seca] = self.DicP[nom]  
        #self.DicP[nom] = [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]

    #---------------------------------------------------------------------------------------------------------------
    def Conver_Pxv(self,A,nom,lien):
        
        [Vdx,Sec,self.VPx,noma,modela,seca] = self.DicP[nom]  
        [self.Vd1x,self.Vd2x]=Vdx
        self.DicP[nom] = [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]
        
    #---------------------------------------------------------------------------------------------------------------
    def Conver_Pxvr(self,A,nom,lien):
        
        [Vdx,self.Secx,self.VPx,noma,modela,seca] = self.DicP[nom]
        [self.Vd1x,self.Vd2x]=Vdx
    #---------------------------------------------------------------------------------------------------------------

    def Conver_Relier(self,A,nom,lien)   :
      
        self.CodeP.pop(self.iCodeP)
        [Rc,h] = ConvNFloat(A,2)

    #BUG : je ne peux pas utiliser la fonction CodePInsert à cet endroit!    
        LTex =[   
            "Pn : X0",
            "Pc = "+str(h)+":X1",
            "Pxvr: "+nom,
            "Vc = "+str(h),  
            "Ci = "+str(Rc),
            "VPx: X1",
            "Ci = "+str(Rc),
            "VPx: X0"   
        ]
        
        CodeInsert(self.CodeP,self.iCodeP,LTex)
        self.ICodeP += 7
        self.iCodeP -=1
    #---------------------------------------------------------------------------------------------------------------
    def Conver_ScPar(self,A,nom,lien):
        
        [R1,e1] = self.Secx  
        [R2,e2,L,N]=ConvNFloat(A,4)
        print(self.Secx)
        if N<eps : N=4
        N=int(N)
        self.CodeP.pop(self.iCodeP)
        a=(R2-R1)/(L*L)
        b = L / sqrt(N)
        de = (e2-e1)/L
        for i in range(0,N):
            k = float(N-i)
            dL = b*(sqrt(k+1)-sqrt(k))
            xk = L*sqrt(k/N)
            R = R1 + a*xk*xk
            e = e1 + de*xk
            self.CodeP.insert(self.iCodeP,"Sc= "+str(R)+","+str(e)+","+str(dL))
       
        self.iCodeP +=(N-1)
        self.ICodeP +=(N-1)
        self.Secx = [R2,e2]  
        
     #---------------------------------------------------------------------------------------------------------------
    def Conver_Sc(self,A,nom,lien):

        if self.model in ["TUBE","TUYAU3M"]:
            [R,e,L]=ConvNFloat(A,3)
            self.Secx=[R,e]
        else:
            AfficherErreur(["Prise en compte des changements de section uniquement avec les TUBE pour le moment"])
        
        Vd2 =  VectRatio(self.Vd2x,L)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd2]])

        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]
        
     #---------------------------------------------------------------------------------------------------------------
    def Conver_Sce(self,A,nom,lien):

        if self.model in ["TUBE","TUYAU3M"]:
            [R1,e1]=self.Secx
            [R2,e2,L,ad]=ConvNFloat(A,4)
            self.Secx=[R2,e2]
        else:
            AfficherErreur(["Prise en compte des changements de section uniquement avec les TUBE pour le moment"])
        
        Ve =  VectDih(abs(R2-R1),self.Vd1x,self.Vd2x,ad,0)
        Vd2 =  VectRatio(self.Vd2x,L)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd2],[1,Ve]])

        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]
        
        
    #---------------------------------------------------------------------------      
    def Conver_Section(self,A,nom,lien):   
        self.Secx=nom
        

    #---------------------------------------------------------------------------
    def Conver_Si(self,A,nom,lien):

        if self.model in ["TUBE","3D","BARRE","TUYAU3M","TUYAU6M"]:
            [R,e]=ConvNFloat(A,2)
            self.Secx=[R,e]
        elif self.model == "CABLE":
            [S]=ConvNFloat(A,1)
            R = sqrt(S/math.pi)
            self.Secx =[R,R]
        elif self.model =="POUTRE_RECTANGLE":
            [Lmax,Lmin,e1,e2]=ConvNFloat(A,4)
            self.Secx=[Lmax,Lmin,e1,e2]
            

    #---------------------------------------------------------------------------
    def Conver_Te(self,A,nom,lien):
        
        [Rp,ep,ad,Lc,Lp]=ConvNFloat(A,5)
        
        LTex=[
        "NbElement=1",
        "Vc="+str(Lc)+":"+nom+"o",
        "VPiq="+str(Rp)+","+str(ep)+","+str(ad)+",0,"+str(Lp/2)+":"+nom+"p1",
        "Pxvr:"+nom+"p1",
        "Vc="+str(Lp)+":"+nom+"p>s",
        "Pxvr:"+nom+"o",
        "Vc="+str(Lc)+":"+nom+"c>s",
        "NbElement=8",
        ]
        
        self.CodeP.pop(self.iCodeP)
        n=len(LTex)
        CodeInsert(self.CodeP,self.iCodeP,LTex)
        self.ICodeP += n-2
        self.iCodeP -=1

    #---------------------------------------------------------------------------
    def Conver_Table(self,A,nom,lien):
        LNom=nom.split(',')
        
        Lx=TrouverLigne(self.CodeA,"#TABLEAU")
        self.CodeP.pop(self.iCodeP)
        CodeInsert(self.CodeA,Lx,[
        "T_DEPL=POST_RELEVE_T(",
        "     ACTION=(",
        "         _F(",
        "             INTITULE='Disp',",
        "             GROUP_NO=('GPOINTS'),",
        "             RESULTAT=RES_PP,",
        "             NOM_CHAM='DEPL',",
        "             NOM_CMP=('DX','DY','DZ','DRX','DRY','DRZ',),",
        "             OPERATION='EXTRACTION',",
        "             ),",
        "         ),",
        ");",
        "",
        "T_FORCES=POST_RELEVE_T(",
        "     ACTION=(",
        "         _F(",
        "             INTITULE='Forces',",
        "             GROUP_NO=('GPOINTS'),",
        "             RESULTAT=RES_PP,",
        "             NOM_CHAM='SIEF_NOEU',",
        "             NOM_CMP=('N','VY','VZ','MT','MFY','MFZ',),",
        "             OPERATION='EXTRACTION',",
        "             ),",
        "         ),",
        ");",
        "",
        "IMPR_TABLE(TABLE=T_DEPL,",
        "         TITRE='Displ',",
        "         NOM_PARA=('NOEUD','DX','DY','DZ','DRX','DRY','DRZ'),)",
        "",
        "IMPR_TABLE(TABLE=T_FORCES,",
        "         TITRE='Forces',",
        "         NOM_PARA=('NOEUD','N','VY','VZ','MT','MFY','MFZ'),)",
        ])

        self.ICodeP-=1
        self.iCodeP-=1


         
    #---------------------------------------------------------------------------    
    def Conver_Tore(self,A,nom,lien):
        
        [R,N]=ConvNInt(A,2)  
        if N<2: N=2  

        self.CodeP.pop(self.iCodeP)
        ac=360/N
        for i in range(0,N+1):
            self.CodeP.insert(self.iCodeP,"Ca= "+str(R)+","+str(ac)+",0:"+nom+str(N-i))
        self.ICodeP+=N-2
        self.iCodeP+=-1

        
    #---------------------------------------------------------------------------
    def Conver_VPiq(self,A,nom,lien):

        [Rp,ep,ad,bd,rc] =  ConvNFloat(A,5)
        SecPiq = [Rp,ep]
        [Rc,ec]=self.Secx

        Vd3mp =  VectDih(Rc,self.Vd1x,self.Vd2x,ad,bd)
        Vd3s = VectString2(Vd3mp)
        SPiqs= VectString2([Rp,ep])

        VPp =  AddVect([[1,self.VPx],[1,Vd3mp]])  

        self.DicP[nom] =  [[self.Vd2x,Vd3mp],SecPiq,VPp,"","",""]  
        
#        LTex=[
#        "Pn:X",
#        "Mat:RIGIDE",
#        "Si="+SPiqs,
#        "V="+Vd3s+":"+nom,
#        "Mat:"+self.matx,
#        "Pxvr:X",
#        ]
#        
#        self.CodeP.pop(self.iCodeP)
#        n=len(LTex)
#        CodeInsert(self.CodeP,self.iCodeP,LTex)
#        self.ICodeP += n-2
#        self.iCodeP -=2
        
        
    #---------------------------------------------------------------------------
    def Conver_VPoq(self,A,nom,lien):
      
        [Rc,ec,ad,bd,rc,Lc] =  ConvNFloat(A,5)
        
        [Rp,ep]=self.Secx
        self.Secx=[Rc,ec]
        VPoq = "VPoq" + str(self.nP)

        Vd3x =  VectDih(Lc,self.Vd1x,self.Vd2x,ad,bd)
        Vd3xo= VectOpp(Vd3x)
        Vd3xs =  VectString2(Vd3x)


        Pc1 = nom+"_1"
        Pc2 = nom+"_2"
        Pcm = nom+"_m"
  
        # Modification  AVANT VPoq     
        v1=self.CodeP[self.iCodeP-1]
        [Cd1,A1,nom1,lien1]=Fractionner(v1)

        if Cd1 != "V": AfficherErreur(["Il faut un V avant le VPoq"])
        
        V1 = VectNum(A1)
        LV1=NormVect(V1)
        if LV1-Rc < 0 : 
            AfficherErreur([
                "Configuration impossible avec ce rayon pour le collecteur",
                "Valeur du V précédent trop faible"
            ])
        Vp = VectRatio(V1,LV1-Rc)
        Vps = VectString2(Vp)
        tex1="V="+Vps
        if nom1 != "":
            tex1 += ":"+nom1
        
        self.VPx=AddVect([[1,self.VPx],[-Rc,self.Vd2x]])
        
        VPx1=AddVect([[1,self.VPx],[Lc,Vd3x]])
        VPx2=AddVect([[1,self.VPx],[-Lc,Vd3x]])
        
        self.DicP[Pc1] =  [[self.Vd2x,Vd3x],[Rc,ec],VPx1,"","",""]
        self.DicP[Pc2] =  [[self.Vd2x,Vd3xo],[Rc,ec],VPx1,"","",""]
        
#        TexLien=""
#        if lien!="":TexLien=">"+lien
#        
#        LTex=[
#        tex1+TexLien,
#        "Mat:RIGIDE",
#        "Vc="+str(Rc)+":"+Pcm,
#        "Mat:"+self.matx,
#        "Si="+str(Rc)+","+str(ec), 
#        "Vd="+str(Lc)+","+str(ad)+","+str(bd)+":"+Pc1+TexLien,
#        "Px:"+Pcm,
#        "Vd2xOpp",
#        "Vc="+str(Lc)+":"+Pc2+TexLien,
#        ]
#        
#        self.CodeP.pop(self.iCodeP)
#        self.CodeP.pop(self.iCodeP-1)
#        n=len(LTex)
#        CodeInsert(self.CodeP,self.iCodeP-1,LTex)
#        self.ICodeP += n-2
#        self.iCodeP -=1



    #---------------------------------------------------------------------------    
    def Conver_VPx(self,A,nom,lien):
    
        VPx0=self.VPx
        [Vdx0,Secx0,self.VPx,noma,modela,seca] = self.DicP[nom]
        self.Vd2x = Vect(VPx0,self.VPx)
        Vd2xs=VectString2(self.Vd2x)

        tex="V="+Vd2xs
        if nom!="":tex+=":"+nom
        self.CodeP[self.iCodeP]=tex


    #---------------------------------------------------------------------------    
    def Conver_V(self,A,nom,lien):
        
        Vd3x = VectNum(A)
        self.VPx = AddVect([[1,self.VPx],[1,Vd3x]])
        
        if self.LastCd not in ["P","Px","Pxvr"]:
            if VerifierColinea(self.Vd2x,Vd3x) == 0 : 
                self.Vd1x=self.Vd2x
                self.Vd2x=Vd3x
        else:
            #print("P avant")
            self.Vd2x=Vd3x
    
                
        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]    
        
    #---------------------------------------------------------------------------  
    def Conver_Vanne(self,A,nom,lien):

        [L,masse,h,ad]=ConvNFloat(A,4)

        Vd2 =  VectRatio(self.Vd2x,L)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd2]])

        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]


    #---------------------------------------------------------------------------
    def Conver_VcPx(self,A,nom,lien):

        L=float(A[0])
        VPx0=self.VPx
        nomx=""
        if "," in nom: [nom,nomx]=nom.split(",")
        [Vdx0,Secx0,VPx1,noma,modela,seca] = self.DicP[nom]
        self.Vd2x = Vect(VPx0,VPx1)
        Vdxc=VectRatio(self.Vd2x,L)
        self.VPx=AddPVect(VPx0,Vdxc)

        if nom != "": self.DicP[nomx] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]  



    #---------------------------------------------------------------------------
    def Conver_VcPxK(self,A,nom,lien):
        k=float(A[0])
        nomx=""
        if "," in nom: [nom,nomx]=nom.split(",")
        [Vdx1,Secx1,VPx1,noma,modela,seca] = self.DicP[nom]

        self.Vd2x = Vect(self.VPx,VPx1)
        LVd2x=NormVect(self.Vd2x)
        LV=LVd2x/k
        Vdxc=VectRatio(self.Vd2x,LV)
        self.VPx=AddPVect(self.VPx,Vdxc)
        tex="V="+VectString2(Vdxc)
        if nomx!="":tex+=":"+nomx
        self.CodeP[self.iCodeP]=tex  


        if nom != "": self.DicP[nomx] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]  

    #---------------------------------------------------------------------------
    def Conver_Vc(self,A,nom,lien):

        [L,ap]=ConvNFloat(A,2)
        Vd2 =  VectRatio(self.Vd2x,L)
        Vd2s = VectString2(Vd2)

        tex="V="+Vd2s
        
        if nom!="":tex+=":"+nom
        if lien!="":tex+=">"+lien

        self.CodeP[self.iCodeP]= tex

        self.VPx =  AddVect([[1,self.VPx],[1,Vd2]])
        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","",""]

        
    #---------------------------------------------------------------------------    
    def Conver_Vd1x(self,A,nom,lien):
        self.Vd1x = ConvNFloat(A,3)
        
    #---------------------------------------------------------------------------
    def Conver_Vd2x(self,A,nom,lien):
        self.Vd2x = ConvNFloat(A,3)
        
    #---------------------------------------------------------------------------
    def Conver_Vd2xOpp(self,A,nom,lien):
        self.Vd2x = VectOpp(self.Vd2x)
        
    #---------------------------------------------------------------------------
    def Conver_Vd(self,A,nom,lien):
        
        [L,ad,ab] = ConvNFloat(A,3)
        Vd3x =  VectDih(L,self.Vd1x,self.Vd2x,ad,ab)
        self.VPx =  AddVect([[1,self.VPx],[1,Vd3x]]) 
        
        Vd3xs = VectString2(Vd3x)

        tex="V="+Vd3xs
        
        if nom!="":tex+=":"+nom
        if lien!="":tex+=">"+lien
        
        self.CodeP[self.iCodeP]= tex

        self.Vd1x = self.Vd2x
        self.Vd2x = Vd3x

        if nom != "": self.DicP[nom] =  [[self.Vd1x,self.Vd2x],self.Secx,self.VPx,"","","",]         
 
    #---------------------------------------------------------------------------    
    def Conver_WireVc(self,A,nom,lien):
        self.iWireVc=True
        self.Conver_Wire(A,nom,lien) 
        self.iWireVc=False

    #---------------------------------------------------------------------------    
    def Conver_Wire(self,A,nom,lien):
    
        if self.iWireVc:
            [L]=ConvNFloat(A,1)
            Vd3x=VectRatio(self.Vd2x,L)
        else:
            Vd3x = ConvNFloat(A,3)

        self.VPx = AddVect([[1,self.VPx],[1,Vd3x]])
        
        if self.LastCd not in ["P","Px","Pxvr"]:
            if VerifierColinea(self.Vd2x,Vd3x) == 0 : 
                self.Vd1x=self.Vd2x
                self.Vd2x=Vd3x
        else:
            #print("P avant")
            self.Vd2x=Vd3x  

    #---------------------------------------------------------------------------    
    def Conver_Wire2Dc(self,A,nom,lien):
        self.Conver_WireVc(A,nom,lien)
     
    #---------------------------------------------------------------------------    
    def Conver_Wire2D(self,A,nom,lien):
        self.Conver_Wire(A,nom,lien)   

    #---------------------------------------------------------------------------    
    def Conver_Wire2Ds(self,A,nom,lien):
        self.Conver_Wire(A,nom,lien)         
            
            
            
            
    #---------------------------------------------------------------------------
    def Inserer_LesVs_iMat(self):
        
        if  self.LesVs_iMat !=[]:
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]

            for m in self.LesVs_iMat :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            LTex.extend([
            "       "+tex,
            "   ),",
            "   MATER="+self.matx+",",
            "),",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#CHMAT_AFFE")
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            Lx =  TrouverLigne(self.CodeA,"#CHMATH_AFFE")
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            self.LesVs_iMat =[]
            
    #---------------------------------------------------------------------------
    def Inserer_LesVs_iTemp(self):
        
        if  self.LesVs_iTemp !=[]:            
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]
           
            
            for m in self.LesVs_iTemp :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            LTex.extend([
            "       "+tex,
            "   ),",
            "   NOM_CMP='TEMP',",
            "   VALE="+str(self.Temp)+",",          
            "),",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#CHAMP_TEMP")
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            self.LesVs_iTemp =[]
            
    #---------------------------------------------------------------------------
    def Inserer_LesVs_iPress(self):
        
        if  self.LesVs_iPress !=[]:    
            if self.model in ["TUYAU3M","TUYAU6M"]:
                Lx =  TrouverLigne(self.CodeA,"#FORCE_TUYAU")    
                tex=""
                nc=0
                LTex=[
                "_F(",
                "   GROUP_MA=(",
                ]
                 
                for m in self.LesVs_iPress :
                    nc+=len(m)+4       
                    tex += "'"+m+"', "
                    if nc > 40:
                        LTex.append("       "+tex)
                        tex=""
                        nc=0
                LTex.EXTEND([
                "       "+tex,
                "   ),",
                "   PRES="+str(self.Press)+",",         
                "),",
                ])
                
                CodeInsertI(self.CodeA,Lx,2,LTex)
            
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]
           
            for m in self.LesVs_iPress :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            LTex.extend([
            "       "+tex,
            "   ),",
            "   NOM_CMP='TEMP',",
            "   VALE="+str(self.Press)+",",          
            "),",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#CHAMP_PRESS")
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            #Création du champ contrainte liée à la pression
            tex=""
            nc=0
            LTex=[]
            LTex.append("_F(")
            LTex.append("   GROUP_MA=(")
            [R,e]=self.Secx
            SIGP=self.Press*R/2/e  
            for m in self.LesVs_iPress :

                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            LTex.extend([
            "       "+tex,
            "   ),",
            "   NOM_CMP='TEMP',",
            "   VALE="+str(SIGP)+",",          
            "),",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#CHAMP_SIGP")
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            self.LesVs_iPress =[]
             

    #--------------------------------------------------------------------------- 
    def Inserer_LesRONDs_iSec(self):
        
        self.Inserer_LesVs_iPress()
           
        if  self.LesRONDs_iSec !=[]:
            [R,e]=self.Secx
            secxs = VectString2(self.Secx)
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]

            for m in self.LesRONDs_iSec :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="": LTex.append("       "+tex)
            LTex.append("   ),")
            
            if self.model=="CABLE":
                LTex.extend([
                "   SECTION ="+str(math.pi*R*R)+",",
                "   N_INIT = 10",
                "),",
                ])
            else:
                LTex.extend([
                "   SECTION ='CERCLE',",
                "   CARA=('R','EP',),",
                "   VALE=("+ secxs +"),",
                "),",
                ])
            LTex.append("")
            Lx =  TrouverLigne(self.CodeA,"#SECTION_"+self.model)
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            
            # Force linéique constante liée  au contenu         
            if self.iRhoV and self.model in ["TUBE","TUYAU3M","TUYAU6M"]:
                [R,e]=self.Secx
                Flz = math.pi*(R-e)*(R-e)*self.RhoV*self.Vg[2]*1E-6
                
                tex=""
                nc=0
                LTex=[
                "_F(",
                "   GROUP_MA=(",
                ]

                for m in self.LesRONDs_iSec :
                    nc+=len(m)+4       
                    tex += "'"+m+"', "
                    if nc > 40:
                        LTex.append("       "+tex)
                        tex=""
                        nc=0
                if tex!="": LTex.append("       "+tex)
                LTex.extend([
                "    ),",
                "   FZ=" + str(Flz) +",",
                "),",
                "",
                ])
                Lx =  TrouverLigne(self.CodeA,"#FORCE_CONTENU")
                CodeInsertI(self.CodeA,Lx,2,LTex)   
            self.LesRONDs_iSec =[]
            
       
            
        # Traitement des sections liées aux équipements    
        if  self.LesRONDx4s_iSec !=[]:
            [R,e]=self.Secx
            e*=4
            secxs = VectString2(self.Secx)
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]

            for m in self.LesRONDx4s_iSec :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="": LTex.append("       "+tex)
            LTex.extend([
            "   ),",
            "   SECTION ='CERCLE',",
            "   CARA=('R','EP',),",
            "   VALE=("+ secxs +"),",
            "),",
            "",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#SECTION_"+self.model)
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            
            # Force linéique constante liée  au contenu         
            if self.iRhoV and self.model in ["TUBE","TUYAU3M","TUYAU6M"]:
                Flz = math.pi*(R-e)*(R-e)*self.RhoV*self.Vg[2]*1E-6
                tex=""
                nc=0
                LTex=[
                "_F(",
                "   GROUP_MA=(",
                ]

                for m in self.LesRONDx4s_iSec :
                    nc+=len(m)+4       
                    tex += "'"+m+"', "
                    if nc > 40:
                        LTex.append("       "+tex)
                        tex=""
                        nc=0
                if tex!="": LTex.append("       "+tex)
                LTex.extend([
                "   ),",
                "   FZ=" + str(Flz) +",",
                "),",
                "",
                ])
                Lx =  TrouverLigne(self.CodeA,"#FORCE_CONTENU")
                CodeInsertI(self.CodeA,Lx,2,LTex)         
            
            
            self.LesRONDx4s_iSec =[]
      
    #--------------------------------------------------------------------------- 
    def Inserer_LesRECTs_iSec(self):
           
        if  self.LesRECTs_iSec !=[]:
            [Hy,Hz,ey,ez,a]=ConvNFloat(self.Secx,5)
            
            if ey==0 and ey==0: 
                iRectPlein=True
                secxs = VectString2(self.Secx[:2])
            else:
                iRectPlein=False
                secxs = VectString2(self.Secx[:4])
                
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]

            for m in self.LesRECTs_iSec :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="": LTex.append("       "+tex)
            LTex.append("   ),")

            if iRectPlein:
                LTex.extend([
                "   SECTION='RECTANGLE',",
                "   CARA=('HY','HZ'),",
                "   VALE=("+secxs+"),",
                "),",
                ])
            else:
                LTex.extend([
                "   SECTION='RECTANGLE',",
                "   CARA=('HY','HZ','EPY','EPZ'),",
                "   VALE=("+secxs+"),",
                "),",
                ])
                
            LTex.append("")
            Lx =  TrouverLigne(self.CodeA,"#SECTION_POUTRE")
            CodeInsertI(self.CodeA,Lx,2,LTex) 
            
            self.LesRECTs_iSec =[]

    #--------------------------------------------------------------------------- 
    def Inserer_LesPOUTREs_iSec(self):
           
        if  self.LesPOUTREs_iSec !=[]:         
            secxs = VectString2(LesSections[self.Secx][2])
                
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]

            for m in self.LesPOUTREs_iSec :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="": LTex.append("       "+tex)
            LTex.append("   ),")

            LTex.extend([
            "   SECTION='GENERALE',",
            "   CARA=('A','IZ','IY','AY','AZ','EY','EZ','JX','JG','IYR2','IZR2','RY','RZ','RT',),",
            "   VALE=("+secxs+"),",
            "),",
            ])
                
            LTex.append("")
            Lx =  TrouverLigne(self.CodeA,"#SECTION_POUTRE")
            CodeInsertI(self.CodeA,Lx,2,LTex) 
            
            self.LesPOUTREs_iSec =[]    
            
            
            
    #--------------------------------------------------------------------------- 
    def NommerNoeud(self,nom):   
        Pn = "Pn_"+str(self.nP)
        if nom != "": 
            Pn = nom 
            if  nom[0]=="P":
                AfficherErreur(["Les noms des noeuds ne doivent pas commencer par un P"])
        self.Pn=Pn
        return Pn
        
#-------------------------------------------------------------------------------     
#-------------------------------------------------------------------------------       
            
    #---------------------------------------------------------------------------
    def X__LireFichiers(self):
        

        AfficherTitre(1,"Lecture des fichiers")
        AfficherTitre(2,"Lecture du fichier .pkl")

        self.CodeP=[]
        
        f = open(fichier_pkl)
        code = f.readlines()
        f.close()

        for v in code :
            v=v[:-1]
            self.CodeP.append(v)
        del(code[:])
        
        
        AfficherTitre(2,"Lecture de TUBA_BASE.txt")
        
        self.CodeA =[]
        
        f = open(TubaRepertoire+"/TUBA_BASE.txt", "r")
        code= f.readlines()
        f.close()
          
        for v in code :
            v=v[:-1]
            self.CodeA.append(v)


    #---------------------------------------------------------------------------
    def X__SimplifierCode(self):

        AfficherTitre(1,"Simplification du code")
        Lire=0
        CodeP2=[]
        self.model="TUYAU3M"
        
        for v in self.CodeP:
            v=v.strip()
            # Suppression des lignes vides
            if v == ""  or v[0] == "#":
                continue
        
            [Cd,A,nom,lien] = Fractionner(v)  
        
            # Simplification de la ligne en enlevant tous les espaces
            Cd = Cd.strip()
            nom = nom.strip()
            
            if Cd=="FIN":
                break

            # Enregistement des lignes en commandes essentielles
            if "_" in Cd:
                [Cd,model]=Cd.split("_")
                v2=Reconstruire(Cd,A,nom,lien)
                L=[ "Model:"+model,
                    v2,
                    "Model:"+self.model ]
                CodeAppend(CodeP2,L)
            elif Cd=="Model":
                CodeP2.append(v)
                self.model=nom
            else:
                v2=Reconstruire(Cd,A,nom,lien)
                CodeP2.append(v2)
               
        
        self.CodeP = CodeP2[:]   

   #---------------------------------------------------------------------------
    def X__TransformerVariables(self):
        DVar={}

        AfficherTitre(1,"Transformation des variables:")
        
        #Création de la liste des variables
        AfficherTitre(2,"Création de la liste des variables:")
        self.ICodePl=len(self.CodeP)
        self.iCodePl = 0
        while self.iCodePl < self.ICodePl:
            v = self.CodeP[self.iCodePl]
            [Cd,A,nom,lien] =  Fractionner(v)
            if Cd == "Var":
                if nom=="":AfficherErreur(["Nom de variable absent!"])
                val=A[0]
                DVar[nom]=val
                self.CodeP.pop(self.iCodePl)
                self.iCodePl-=1
                self.ICodePl-=1
            self.iCodePl +=1
        
        #Remplacement des variables par leur valeur
        AfficherTitre(2,"Remplacement des variables par leur valeur")
        CodeP2=[]
        for v in self.CodeP:
            [Cd,A,nom,lien]=Fractionner2(v)
            if A!="":
                for var in DVar:
                    val = DVar[var]
                    if var in A :
                        A=ReplaceInString2(A,var,val)
            if nom!="":
                for var in DVar:
                    val = DVar[var]     
                    var2="("+var+")"
                    if var2 in nom :
                        nom=ReplaceInString2(nom,var2,val)
            tex = Reconstruire2(Cd,A,nom,lien)
            CodeP2.append(tex)    
            
            
        self.CodeP = CodeP2[:]    
        AfficherListe(self.CodeP)
            
        AfficherTitre(2,"Remplacement des variables dans les parenthèses de Wire")
        CodeP2=[]
        iWire=False
        for v in self.CodeP:
            [Cd,A,nom,lien]=Fractionner2(v)
            if Cd in LesWires: 
                iWire=True
            elif v == "]":
                iWire=False               
            elif iWire:
                for var in DVar:
                    val = DVar[var]
                    if var in v :
                        v=ReplaceInString2(v,var,val)

            CodeP2.append(v)    

        self.CodeP = CodeP2[:]
        
        #AfficherListe(self.CodeP)
            
   
 
        
    #---------------------------------------------------------------------------
    def X__ConvertirWire(self):

        AfficherTitre(1,"Conversion des Wires")
        Lire=0
        CodeP2=[]
        ICodeP=len(self.CodeP)
        iCodeP=0
        
        while iCodeP<ICodeP:
            v = self.CodeP[iCodeP]
            [Cd,A,nom,lien] =  Fractionner(v)
            if Cd in LesWires:   
                iCodeP+=1
                v1 = self.CodeP[iCodeP]
                v1=v1.strip()
                if v1 !="[":
                    AfficherErreur(["le texte du Wire doit être en []"])
                else:
                    tex=""
                    while True:
                        iCodeP+=1
                        v2 = self.CodeP[iCodeP]
                        v2=v2.strip()
                        if v2!="]":
                            tex=tex+v2+"&"
                        else:
                            tex=tex[:-1]
                            v=Reconstruire(Cd,A,tex,lien)
                            CodeP2.append(v)
                            iCodeP+=1
                            break
            else:
                CodeP2.append(v)
                iCodeP+=1
            
        self.CodeP = CodeP2[:]             
                        
        AfficherListe(self.CodeP)                    
        

 


    #---------------------------------------------------------------------------
    def X__TransformerBoucles(self):
        
        AfficherTitre(1,"Transformation des boucles")
        # Vérification de la cohérence des boucles d'itération
        AfficherTitre(2,"Vérification de la cohérence des boucles d'itération")    
        nBoucle=0
        self.ICodeP=len(self.CodeP)
        self.iCodeP=0
        ouvre=1
        while self.iCodeP < self.ICodeP:
            v=self.CodeP[self.iCodeP]
            [Cd,A,nom,lien]=Fractionner(v)
            if Cd =="X":
                nA=len(A)
                if not(nA in [2,3])  or nom == "":
                    AfficherErreur([" X=id,if,it:k ou X=id,if:k"]  )
                ouvre = 1    
            elif Cd =="[":
                nBoucle+=1
                ouvre = 0
            elif Cd =="]":
                if ouvre == 1 or nBoucle <= 0 :
                    AfficherErreur(["Boucle [] incohérentes : Après X on attends ["])
                nBoucle-=1
            self.iCodeP +=1

        if nBoucle!=0 : 
            AfficherErreur(["Boucle [] incohérentes : nombre de  [ != de ceux de ]"])

        
        # Transformation des itérations
        AfficherTitre(2,"Transformation des itérations")   

        while 1:
            CodeP2=[]
            CodeIter=[]
            boucle = 0
            yaX=0
            for v in self.CodeP:
                [Cd,A,nom,lien] =  Fractionner(v)
                if boucle == 0:
                    if Cd == "X":
                        yaX=1
                        print(A)
                        [n1,n2,dn]=ConvNIntEval(A,3)
                        if dn==0 : dn = 1
                        k=nom
                    elif Cd == "[":
                        boucle = 1
                    else:
                        CodeP2.append(v)
                
                else:
                    if Cd == "[":
                        boucle += 1
                    elif Cd == "]":
                        boucle -= 1
                        
                    if boucle == 0:

                        CodePIter=[]
                        for i in range(n1,n2+1,dn):
                            for w in CodeIter:
                                [Cd2,A2,nom2,lien2] =Fractionner2(w)

                                if k in A2:
                                    A2=ReplaceInString2(A2,k,i)

                                if k in nom2:
                                    nom2=ReplaceInString3(nom2,k,i)
                                    
                                w2 =  Reconstruire2(Cd2,A2,nom2,lien2)
                                CodePIter.append(w2)
                                    
                        CodeP2.extend(CodePIter)
                        CodeIter=[]
                        
                    else:
                        CodeIter.append(v)
                        
            self.CodeP = CodeP2[:]
            if yaX==0:break


    #---------------------------------------------------------------------------
    def X__VerifierCode_1(self):

        AfficherTitre(1,"Première Vérification")
        
        self.ICodeP=len(self.CodeP)
        self.iCodeP=0
        nPara=0
        nAcco=0
        self.LesCd=[]
        while self.iCodeP < self.ICodeP:
            
            v = self.CodeP[self.iCodeP]
            [Cd,A,nom,lien]= Fractionner(v)
            self.LesCd.append(Cd)
            if Cd == "[" : nPara +=1
            if Cd == "]" : nPara -=1        
            if Cd == "{" : 
                nAcco +=1
                self.iCodeP1 = self.iCodeP
            if Cd == "}" : 
                nAcco -=1    
                dn = self.iCodeP - self.iCodeP1
                if dn != 9 : AfficherErreur(["Les lyres doivent être composées de 9 commandes"])
            
            if nAcco not in [0,1] : AfficherErreur(["Accolade {} oubliés"])
            if nPara < 0 : AfficherErreur(["Enchainement des  parenthèses de répétition incohérent"])    
            
            self.iCodeP +=1
            
            
        if nAcco != 0 : AfficherErreur(["Accolade {} oubliés"])  
        if nPara != 0 : AfficherErreur(["Enchainement des  parenthèses de répétition incohérent"])  
            
        
        if "P" not in self.LesCd: 
            AfficherErreur(["Il faut au moins définir un point de départ"])
            
# A modifier:
#        if ("Vc" in self.LesCd or "Vd" in self.LesCd or "Ca" in self.LesCd) and "Si" not in self.LesCd:
#            AfficherErreur(["Il faut définit au moins définir une section initiale"])   
                     

        LesCdTex = ""
        for Cd in self.LesCd:
            LesCdTex += Cd+" "
        
        if "Ci Vc " in LesCdTex : AfficherErreur(["Ci ne peut pas être suivie de Vc!"])
        
            
        if self.LesCd[-1] in ["Ci","Piq"]:
            AfficherErreur(["Le code ne peut pas se terminer avec cette commande"])
        


    #---------------------------------------------------------------------------
    def X__ConvertirCode_1(self):
        AfficherTitre(1,"Conversion du code 1")
        self.conver = 1
        self.Vd1x=self.Vd1x0
        self.Vd2x=self.Vd2x0
        self.model="TUYAU3M"
        nBoucle=0

        self.ICodeP = len(self.CodeP)
        self.iCodeP=0
        while self.iCodeP<self.ICodeP:
            v = self.CodeP[self.iCodeP]
            [Cd,A,nom,lien]= Fractionner(v)
            #print(str(self.iCodeP)+": "+v)
            if "_" in Cd:
                C=Cd.split("_")
                Cd=C[0]
            if Cd not in LesCdConver2:
                tex = "Conver_"+Cd+"("+VectString(A)+",\""+nom+"\",\""+lien+"\")"	
                try:
                    print(str(self.iCodeP)+":"+tex)
                    exec("self."+tex)
                except(AttributeError):
                    pass

            if Cd in LesCdGeo: self.LastCd = Cd
            self.iCodeP +=1

#        AfficherListe(self.CodeP)
#        exit()
        
    #---------------------------------------------------------------------------
    def X__ConvertirCode_2(self):
        AfficherTitre(1,"Conversion du code 2")
        self.VPx=[0,0,0]
        self.Vd1x=self.Vd1x0
        self.Vd2x=self.Vd2x0
        self.conver = 2
        self.model="TUYAU3M"


        self.ICodeP = len(self.CodeP)
        self.iCodeP=0
        while self.iCodeP<self.ICodeP:
            v = self.CodeP[self.iCodeP]
            [Cd,A,nom,lien]= Fractionner(v)
            if "_" in Cd:
                C=Cd.split("_")
                Cd=C[0] 
            tex = "Conver_"+Cd+"("+VectString(A)+",\""+nom+"\",\""+lien+"\")"
            try:
                print(str(self.iCodeP)+":"+tex)
                exec("self."+tex)
            except(AttributeError):
                print("Commande non géométrique et non .comm")
                pass

            if Cd in LesCdGeo: self.LastCd = Cd
               
            self.iCodeP +=1

            
            

    #---------------------------------------------------------------------------
    def X__EvaluerFormules(self):

        AfficherTitre(1,"Evaluation des formules:")
        
        CodeP2=[]
        for v in self.CodeP:
            [Cd,A,nom,lien]=Fractionner(v)
            A2=[]
            for p in A:
                if "/" in p or "*" in p or "+" in p or "-" in p:
                    A2.append(eval(p))
                else:
                    A2.append(p)
    #        if "/" in nom or "*" in nom or "+" in nom or "-" in nom:
    #            nom=eval(nom)
            v2=Reconstruire(Cd,A2,nom,lien)
            CodeP2.append(v2)

        self.CodeP = CodeP2[:]
        

    #---------------------------------------------------------------------------
    def X__VerifierCode_2(self):
        
        self.nDDL = 0
        nBoucle=0
        AfficherTitre(1,"Vérification de syntaxe")
        
        self.ICodeP=len(self.CodeP)
        self.iCodeP=0
        
        while self.iCodeP < self.ICodeP:
            
            v = self.CodeP[self.iCodeP]
            [Cd,A,nom,lien]= Fractionner(v)
            
            tex = "Verifier_"+Cd+"(self,"+VectString(A)+",\""+nom+"\",\""+lien+"\")"
            print(tex)
            exec(tex)
            self.iCodeP +=1

 
        #-----------------------------------------------------------------------
        AfficherTitre(2,"Vérification du nombre de DDL")
        if self.nDDL < 6 :
            print("Info : Nombre de DDL bloqués insuffisants pour pouvoir lancer un calcul!")



    #---------------------------------------------------------------------------
    def X__VerifierCoherence(self):

        self.LesCd =[]
        AfficherTitre(1,'Vérification de la cohérence des commandes')
        self.ICodeP=len(self.CodeP)
        self.iCodeP=0
        
        while self.iCodeP < self.ICodeP:
            
            v = self.CodeP[self.iCodeP]
            [Cd,A,nom,lien]= Fractionner(v)
            if not(Cd in ["Model"]):
                self.LesCd.append(Cd)  
            self.iCodeP+=1


        if "Mat" not in self.LesCd:
            self.CodeP.insert(0,"Mat :ACIER") 

        Cd0 = self.LesCd[-1]
        if Cd0 in ["Ci","Piq"]:
            AfficherErreur(["Dernière commande incorrecte"])

        
        n = len(self.LesCd)
        self.LesCd.append("FIN")
        error=0
        i=1
        if n>2: 

                LesIndex=TrouverIndex(self.LesCd ,"Piq")
                for i in LesIndex:
                    iAvant= self.LesCd [i-1] not in ["Vc","V"]
                    iApres = self.LesCd [i+1] not in ["Vc","V"]
                    if iAvant == 1 or iApres == 1:
                        AfficherErreur(["Piq doit être entre 2 Vc "])


#                LesIndex=TrouverIndex(self.LesCd ,"Sc")
#                for i in LesIndex[:-1]:
#                    iAvant= self.LesCd [i-1] not in ["Sc","Vc","Ca","V"]
#                    iApres = self.LesCd [i+1] not in ["Sc","Vc","Ca","V"]
#                    if iAvant == 1 or iApres == 1:
#                        AfficherErreur(["Sc doit être entre Sc, Vc et Ca"])

                
                LesIndex=TrouverIndex(self.LesCd ,"Vanne")
                for i in LesIndex:
                    iAvant= self.LesCd [i-1] not in ["Vc","V","Ca","Bride","Sc","VPiq"]
                    iApres = self.LesCd [i+1] not in ["Vc","V","Ca","Bride","Sc","VPiq"]
                    if iAvant == 1 or iApres == 1:
                        AfficherErreur(["Vanne doit être entre Vc, Ca ou Bride"])        
                

                if  self.LesCd [-1] in ["Ci","Piq"]:
                    AfficherErreur(["la dernière commande est incohérente"])
                


    #---------------------------------------------------------------------------
    def X__TraiterCode(self):

        self.model="TUYAU3M"
        self.LesSupports = []
        repere=""
        self.Vd1x=[0,0,1]
        self.Vd2x=[1,0,0]  
        self.iTemp = False
        self.Temp = 0
        self.forme="ROND"
        self.matx="ACIER"

        #self.DicP.clear()
        
        AfficherTitre(1,"TraiterCode")
        
        # Les différentes lignes de CodeS produites seront enregistrée 
        # dans une liste avant d'être enregistrées dans un fichier    CodeS.insert(i,"#V")
        # Pour le code de Salome
        self.ICodeP =len(self.CodeP)
        self.iCodeP = 0

        while 1:
            if self.iCodeP > self.ICodeP-1: break
            # Extraction de la commande
            v = self.CodeP[self.iCodeP]
            Cdx = v
            #print(v)
            #Fractionnement de la ligne
            [Cd,A,nom,lien]=Fractionner(v)
        
            #Mise en commentaire des commandes utilisées dans le code Python
            self.CodeS.append("#"+v)

            tex = "Ajouter_"+Cd+"("+VectString(A)+",\""+nom+"\",\""+lien+"\")"
            print(tex)
            exec("self."+tex)

          
            self.iCodeP += 1
            if Cd in LesCdGeo: self.LastCd = Cd
 
 
        self.X___Traiter_Listes_Non_Vides()
        self.X___Traiter_Materiaux()
        self.X___Traiter_NOEUDs()
        self.X___Traiter_3Ds()
        self.X___Traiter_TUBEs() 
        self.X___Traiter_POUTREs() 
        self.X___Traiter_BARREs()      
        self.X___Traiter_CABLEs()
        self.X___Traiter_TUYAU3Ms() 
        self.X___Traiter_TUYAU6Ms() 
        self.X___Traiter_Liaisons_Solide() 
        self.X___Traiter_Rigides() 
        self.X___Traiter_RESSORTs() 
        self.X___Traiter_Masses() 
        self.X___Traiter_Reducteurs() 
        self.X___Traiter_Concatenation_Maillage() 
        self.X___Traiter_Efforts() 
        self.X___Traiter_Supports() 
        if self.iCalc_Flex : self.X___Traiter_SIF() 

        print
        print 
        print (40 * "-")
        print("CODE CONFORME")
        print      
 
    #---------------------------------------------------------------------------
    def X___Traiter_Listes_Non_Vides(self):
        AfficherTitre(2,"Insertion des dernières données dans CodeA")
        #-----------------------------------------------------------------------  
        self.Inserer_LesRONDs_iSec()
        self.Inserer_LesRECTs_iSec()
        self.Inserer_LesVs_iMat()
        self.Inserer_LesVs_iTemp()
        self.Inserer_LesVs_iPress()
        self.Inserer_LesPOUTREs_iSec()
        #-----------------------------------------------------------------------  
        
        
    #---------------------------------------------------------------------------
    def X___Traiter_Materiaux(self):

        AfficherTitre(3,"Ajout des matériaux utilisés"),
        Lx =  TrouverLigne(self.CodeA,"#DEF_MATERIAU")
        for mat in DicMat:
            [E,nu,rho,alpha,lamba,rhoCp] = DicMat[mat]
            CodeInsert(self.CodeA,Lx ,[
            mat + "=DEFI_MATERIAU(    ",
            "     ELAS=_F(  E=" + str(E*1e3)+",",
            "               NU=" + str(nu)+",",
            "               RHO=" + str(rho*1e-9)+",",
            "               ALPHA=" + str(alpha*1e-6)+",",
            "           ),",
#            "     THER=_F(",
#            "              LAMBDA=" + str(lamba*1e-3)+",",
#            "              RHO_CP=" + str(rhoCp*1e-3)+",",
#            "              ),",
#            "     CABLE=_F()",
            "     );",
            ])
  

    #---------------------------------------------------------------------------
    def X___Traiter_NOEUDs(self):
    
        if self.LesSupports!=[]:
            AfficherTitre(2,"Création du groupe de noeuds des Supports")
            Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_NOEUD")
            tex=""
            LTex=[
            "_F(    NOM='GPOINTS',",
            "       UNION=(",
            ]
            nc=0
            for Supp in self.LesSupports :
                m = Supp[2]
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append(    "           "+tex)
                    tex=""
                    nc=0
            LTex.extend([
            "           "+tex,
            "       ),",
            "),",
            ])
            
            CodeInsertI(self.CodeA,Lx,2,LTex)
 
 
    #---------------------------------------------------------------------------
    def X___Traiter_3Ds(self):    
        if self.Les3Ds!=[]:
            AfficherTitre(3,"Création du groupe de maille des TUBEs")

            Lx =  TrouverLigne(self.CodeA,"#MODELISATION" ) 
                
            LTex=[]
            LTex.append("_F(")
            LTex.append("   GROUP_MA=(")
            tex=""
            nc=0
            for m in self.Les3Ds :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append(    "       "+tex)
                    tex=""
                    nc=0
            if tex!="":LTex.append(    "       "+tex)
            LTex.append("   ),")
            LTex.append("   PHENOMENE='MECANIQUE',")
            LTex.append("   MODELISATION='3D',")
            LTex.append("),")

            
            CodeInsertI(self.CodeA,Lx,2,LTex)
 
        
    #---------------------------------------------------------------------------
    def X___Traiter_TUBEs(self):      
        if self.LesTUBEs!=[]:
            LesD=[]
            LesC=[]
            for m in self.LesTUBEs :
#                if "COU" not in m:  
#                    LesD.append(m)
#                else:
#                    LesC.append(m)
                LesD.append(m)

            if LesD!=[]:
                AfficherTitre(3,"Création du groupe de maille des TUBE droits")
                Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_MAILLE ")
                tex=""
                LTex=[]
                LTex.append("_F(")
                LTex.append("   NOM='GTUBE_D',")
                LTex.append("   TYPE_MAILLE = '1D',")
                LTex.append("   UNION=(")
                tex=""
                nc=0
                for m in LesD :
                    nc+=len(m)+4       
                    tex += "'"+m+"', "
                    if nc > 40:
                        LTex.append("       "+tex)
                        tex=""
                        nc=0
                if tex!="":LTex.append("        "+tex)
                LTex.append("       ),")
                LTex.append("),")
                
                CodeInsertI(self.CodeA,Lx,2,LTex)

                Lx =  TrouverLigne(self.CodeA,"#MODELISATION" ) 
                    
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   GROUP_MA='GTUBE_D',",
                "   PHENOMENE='MECANIQUE',",
                "   MODELISATION='POU_D_T',",
                "),",
                ])
                
            if LesC!=[]:
                AfficherTitre(3,"Création du groupe de maille des Coudes")
                Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_MAILLE ")
                tex=""
                LTex=[]
                LTex.append("_F(")
                LTex.append("   NOM='GTUBE_C',")
                LTex.append("   TYPE_MAILLE = '1D',")
                LTex.append("   UNION=(")
                tex=""
                nc=0
                for m in LesC :
                    nc+=len(m)+4       
                    tex += "'"+m+"', "
                    if nc > 40:
                        LTex.append("       "+tex)
                        tex=""
                        nc=0
                if tex!="":LTex.append("        "+tex)
                LTex.append("       ),")
                LTex.append("),")
                
                CodeInsertI(self.CodeA,Lx,2,LTex)

                Lx =  TrouverLigne(self.CodeA,"#MODELISATION" ) 
                    
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   GROUP_MA='GTUBE_C',",
                "   PHENOMENE='MECANIQUE',",
                "   MODELISATION='POU_C_T',",
                "),",
                ])
                

    #---------------------------------------------------------------------------
    def X___Traiter_POUTREs(self) :    
        if self.LesPOUTREs!=[]:
            AfficherTitre(3,"Création du groupe de maille des poutres rectangle")
            Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_MAILLE ")
            tex=""
            LTex=[
            "_F(    NOM='GPOUTRE',",
            "       TYPE_MAILLE = '1D',",
            "       UNION=("
            ]
            tex=""
            nc=0
            for m in self.LesPOUTREs :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append(    "           "+tex)
                    tex=""
                    nc=0
            LTex.extend([
            "           "+tex,
            "       ),",
            "),",
            ])
            
            CodeInsertI(self.CodeA,Lx,2,LTex)

            Lx =  TrouverLigne(self.CodeA,"#MODELISATION" ) 
                
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   GROUP_MA='GPOUTRE',",
            "   PHENOMENE='MECANIQUE',",
            "   MODELISATION='POU_D_T',",
            "),",
            ])
            
            
    #---------------------------------------------------------------------------
    def X___Traiter_BARREs(self) :    
        if self.LesBARREs!=[]:
            AfficherTitre(3,"Création du groupe de maille des BARREs")
            Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_MAILLE ")
            tex=""
            LTex=[]
            LTex.append("_F(")
            LTex.append("   NOM='GBARRE',")
            LTex.append("   TYPE_MAILLE = '1D',")
            LTex.append("   UNION=(")
            tex=""
            nc=0
            for m in self.LesBARREs :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append(tex)
                    tex=""
                    nc=0
            LTex.append(tex)
            LTex.append("   ),")
            LTex.append("),")
            
            CodeInsertI(self.CodeA,Lx,2,LTex)

            Lx =  TrouverLigne(self.CodeA,"#MODELISATION" ) 
                
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   GROUP_MA='GBARRE',",
            "   PHENOMENE='MECANIQUE',",
            "   MODELISATION='BARRE',",
            "),",
            ])
            
    #---------------------------------------------------------------------------
    def X___Traiter_CABLEs(self):  
        if self.LesCABLEs!=[]:
            AfficherTitre(3,"Création du groupe de maille des CABLEs")
            Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_MAILLE ")
            tex=""
            LTex=[]
            LTex.append("_F(")
            LTex.append("   NOM='GCABLE',")
            LTex.append("   TYPE_MAILLE = '1D',")
            LTex.append("   UNION=(")
            tex=""
            nc=0
            for m in self.LesCABLEs :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="": LTex.append("       "+tex)
            LTex.append("   ),")
            LTex.append("),")
            
            CodeInsertI(self.CodeA,Lx,2,LTex)

            Lx =  TrouverLigne(self.CodeA,"#MODELISATION")  
                
            CodeInsertI(self.CodeA,2,Lx,[
            " _F(",
            "   GROUP_MA='GCABLE',",
            "   PHENOMENE='MECANIQUE',",
            "   MODELISATION='CABLE',",
            "),",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#COMP_ELAS")
            if xCA!=0:
                CodeInsertI(self.CodeA,Lx,2,[
                "_F(",
                "   GROUP_MA = ('GCABLE'  ),",
                "   RELATION = 'CABLE',",
                "   DEFORMATION = 'GROT_GDEP',",
                "), ",
                ])
            
    #---------------------------------------------------------------------------
    def X___Traiter_TUYAU3Ms(self): 
        if self.LesTUYAU3Ms!=[]:
            AfficherTitre(3,"Création du groupe de maille des TUYAU3Ms")
            Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_MAILLE ")
            tex=""
            LTex=[]
            LTex.append("_F(")
            LTex.append("   NOM='GTUYAU3M',")
            LTex.append("   TYPE_MAILLE = '1D',")
            LTex.append("   UNION=(")
            tex=""
            nc=0
            for m in self.LesTUYAU3Ms :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="":LTex.append("       "+tex)
            LTex.append("   "+"),")
            LTex.append("),")
            
            CodeInsertI(self.CodeA,Lx,2,LTex)

            Lx =  TrouverLigne(self.CodeA,"#MODELISATION")    
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   GROUP_MA='GTUYAU3M',",
            "   PHENOMENE='MECANIQUE',",
            "   MODELISATION='TUYAU_3M',",
            "),",
            ])
            
    #---------------------------------------------------------------------------
    def X___Traiter_TUYAU6Ms(self): 
        if self.LesTUYAU6Ms!=[]:
            AfficherTitre(3,"Création du groupe de maille des TUYAU6Ms")
            Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_MAILLE ")
            tex=""
            LTex=[]
            LTex.append("_F(")
            LTex.append("   NOM='GTUYAU6M',")
            LTex.append("   TYPE_MAILLE = '1D',")
            LTex.append("   UNION=(")
            tex=""
            nc=0
            for m in self.LesTUYAU6Ms :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="":LTex.append("    "+tex)
            LTex.append("   ),")
            LTex.append("),")
            
            CodeInsertI(self.CodeA,Lx,2,LTex)

            Lx =  TrouverLigne(self.CodeA,"#MODELISATION")    
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   GROUP_MA='GTUYAU6M',",
            "   PHENOMENE='MECANIQUE',",
            "   MODELISATION='TUYAU_6M',",
            "),",
            ])
            
            
    #---------------------------------------------------------------------------
    def X___Traiter_Liaisons_Solide(self):   
        if self.LesLis!=[]:
            AfficherTitre(3,"Création du groupe des liaisons solide")
            Lx =  TrouverLigne(self.CodeA,"#CREA_GROUPE_MAILLE ")
            tex=""
            LTex=[]
            LTex.append("_F(")
            LTex.append("   NOM='GLIS',")
            LTex.append("   TYPE_MAILLE = '1D',")
            LTex.append("   UNION=(")
            tex=""
            nc=0
            for m in self.LesLis :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="":LTex.append("       "+tex)
            LTex.append("   ),")
            LTex.append("),")
            
            CodeInsertI(self.CodeA,Lx,2,LTex)

            Lx =  TrouverLigne(self.CodeA,"#LIAISON_SOLIDE")     
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   GROUP_MA='GLIS',",
            "),",
            ])            
       
       
    #---------------------------------------------------------------------------
    def X___Traiter_Rigides(self):   
        if self.LesRigides!=[]:
            AfficherTitre(3,"Création des parties rigides")
            tex=""
            nc=0
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]

            for m in self.LesRigides :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            LTex.extend([
            "       "+tex,
            "   ),",
            "   MATER=RIGIDE,",
            "),",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#CHMAT_AFFE")
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            Lx =  TrouverLigne(self.CodeA,"#CHMATH_AFFE")
            CodeInsertI(self.CodeA,Lx,2,LTex)
       
       
       
    #---------------------------------------------------------------------------
    def X___Traiter_RESSORTs(self):   
        if self.LesRESSORTs!=[]:  
            AfficherTitre(3,"Création des RESSORTs")
            Lx =  TrouverLigne(self.CodeA,"#MODELISATION")
            LTex=[]
            
            LTex.append("_F(")
            LTex.append("   GROUP_MA=(")
            nc=0
            tex=""
            for m in self.LesRESSORTs :
                nc+=len(m)+4       
                tex += "'"+m[0]+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="":LTex.append("       "+tex)
            LTex.extend([
            "   ),",
            "   PHENOMENE='MECANIQUE',",
            "   MODELISATION='DIS_T',",
            "),"
            ])
            CodeInsertI(self.CodeA,Lx,2,LTex)  
            
            Lx =  TrouverLigne(self.CodeA,"#MASSE_DISCRET")
            LTex=[]
            nc=0
            tex=""
            for m in self.LesRESSORTs :
                LTex.extend([
                    "_F(",
                    "   GROUP_MA=('"+m[0]+"'), ",
                    "   CARA='K_T_D_L',",
                    "   VALE=("+str(m[1])+",0,0),",
                    "   REPERE='LOCAL',",
                    "),",
                    ])
            CodeInsertI(self.CodeA,Lx,2,LTex)

            Lx =  TrouverLigne(self.CodeA,"#MASSE_DISCRET")
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]
            nc=0
            tex=""
            for m in self.LesRESSORTs :
                nc+=len(m)+5       
                tex += "'"+m[0]+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="":LTex.append("       "+tex)
            LTex.append("   ),")
            LTex.extend([
            "   CARA='M_T_L',",
            "   VALE=(0.,0.,0.,0.,0.,0.,0.,0.,0.,",
            "   0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,),",
            "   REPERE='LOCAL',",
            "),",
            ])
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
       
       
       
    #---------------------------------------------------------------------------
    def X___Traiter_Masses(self):   
        if self.LesMasses!=[]:
            AfficherTitre(3,"Création du points pour affectation d'une masse")
            Lx =  TrouverLigne(self.CodeA,"#CREA_POI1")
            tex=""
            LTex=[]
            for m in self.LesMasses :
                LTex.append("_F(")
                LTex.append("   NOM_GROUP_MA='"+m+"A',")
                LTex.append("   GROUP_NO='"+m+"',")
                LTex.append("),")
            CodeInsertI(self.CodeA,Lx,2,LTex)

# BUG : puisque le groupe de maille *A est créé dans Code_Aster, il n'est plus 
# possible de faire un groupe.
            Lx =  TrouverLigne(self.CodeA,"#MODELISATION")
            LTex=[]
            
            LTex.append("_F(")
            LTex.append("   GROUP_MA=(")
            nc=0
            for m in self.LesMasses :
                nc+=len(m)+4       
                tex += "'"+m+"A', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="":LTex.append("       "+tex)
            LTex.extend([
            "   ),",
            "   PHENOMENE='MECANIQUE',",
            "   MODELISATION='DIS_T',",
            "),"
            ])
            CodeInsertI(self.CodeA,Lx,2,LTex)
            
            Lx =  TrouverLigne(self.CodeA,"#MASSE_DISCRET")
            LTex=[
            "_F(",
            "   GROUP_MA=(",
            ]
            nc=0
            tex=""
            for m in self.LesMasses :
                nc+=len(m)+5       
                tex += "'"+m+"A', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            if tex!="":LTex.append("       "+tex)
            LTex.append("   ),")
            LTex.extend([
            "   CARA='K_T_D_N',",
            "   VALE=(0,0,0),",
            "   REPERE='LOCAL',",
            "),",
            ])
            CodeInsertI(self.CodeA,Lx,2,LTex)


    #---------------------------------------------------------------------------
    def X___Traiter_Reducteurs(self):
        if self.iRhoV and self.iRed_Force_Repartie:
            AfficherTitre(3,"Ajout des forces reparties progressives liees aux réducteur")
            Lx =  TrouverLigne(self.CodeA,"#CHARGEMENT")
            CodeInsertI(self.CodeA,Lx,2,[
            "_F(",
            "   CHARGE=CHARG2F,",
            "#F_CHARG2,",
            "),",
            ]) 
  
  
        #-----------------------------------------------------------------------
#        LTex=[
#        "RESU2=POST_CHAMP(",
#        "   RESULTAT=RESU,",
#        "   TOUT_ORDRE='OUI',",
#        "   GROUP_MA='GTUYAU3M',",
#        "   MIN_MAX_SP=(",
#        "       _F( NOM_CHAM='SIEQ_ELGA',",
#        "           NOM_CMP='VMS',",
#        "           TYPE_MAXI='MAXI',",
#        "           NUME_CHAM_RESU=1,",
#        "       ),",
#        "   ),",
#        ");",
#        ]
#        
#        Lx =  TrouverLigne(self.CodeA,"#TABLEAU")
#        CodeInsert(self.CodeA,Lx,LTex)     

        #-----------------------------------------------------------------------
#        LTex=["EPS=POST_RELEVE_T(ACTION=("]
#        LDicP=self.DicP.keys()
#        
#        for p in LDicP:
#            LTex.extend([
#            "_F(",
#            "   OPERATION='EXTRACTION',",
#            "   INTITULE='TABEPS',",
#            "   RESULTAT=RESU2,",
#            "   NOM_CHAM='SIGM_ELNO',",
#            "   GROUP_NO='"+p+"',",
#            "   NOM_CMP=('SIXX'),",
#            "),",
#            ])
#            
#        LTex.extend([
#        "),);",
#        "IMPR_TABLE(TABLE=EPS)"
#        ])
#        
#        Lx =  TrouverLigne(self.CodeA,"#TABLEAU")
#        CodeInsert(self.CodeA,Lx,LTex)
            
            

    #---------------------------------------------------------------------------
    def X___Traiter_Concatenation_Maillage(self): 
        if self.LTout != []:
            AfficherTitre(2,"Concatétion des maillages")
            tex = "["
            for m in self.LTout :
                tex += ""+m+"M.GetMesh() , "
            tex = tex[:-1]
            tex += "]"
            CodeAppend(self.CodeS,[
            "#",
            "# Création du maillage total",
            "if not(ERREUR):",
            "    Maillage = smesh.Concatenate("+tex+", 1, 0, 1e-05)",
            "    coincident_nodes = Maillage.FindCoincidentNodes( 1e-05 )",
            "    Maillage.MergeNodes(coincident_nodes)",
            "    equal_elements = Maillage.FindEqualElements(Maillage)",    
            "    Maillage.MergeElements(equal_elements)",   
            "    smesh.SetName(Maillage.GetMesh(), 'Maillage')",
            ])
       


     
    #---------------------------------------------------------------------------
    def X___Traiter_Efforts(self):          
        #Evaluation de la dispersion des points
        LesVal=[]
        for P in self.DicP:
            LP = self.DicP[P]
            LesVal.extend(LP[2])
        
        K=max(LesVal) - min(LesVal)
        
        #-----------------------------------------------------------------------
        AfficherTitre(2,"Présentation : Ajout des Torseurs")
        CodeAppend(self.CodeS,["#AJOUT DES FLECHES FORCES"])

        Rf=K/200  

        if self.LesForces != []:
            del(LesVal[:])
            for F in self.LesForces:
                vF = NormVect(F[1])
                LesVal.append(vF)
                
            Fmax = max(LesVal)

            for F in self.LesForces:
                vF = NormVect(F[1])   
                VF = VectRatio(F[1],vF*K/(4*Fmax))
                self.Ajouter_Fleche(F[0],VF,[1,0,0],Rf)
     

        if self.LesMoments != []:
            del(LesVal[:])
            for M in self.LesMoments:
                vM = NormVect(M[1])
                LesVal.append(vM)
                
            Mmax = max(LesVal)

            for M in self.LesMoments:
                vM = NormVect(M[1])   
                VM = VectRatio(M[1],vM*K/(4*Mmax))
                self.Ajouter_Fleche(M[0],VM,[0,0,1],Rf)

#        AfficherListe(self.LesForces)
#        exit()

    #---------------------------------------------------------------------------
    def X___Traiter_Supports(self): 
        if self.LesBi!=[] or self.LesSupports !=[]:
            AfficherTitre(2,"Présentation : Ajout des suppports")
            CodeAppend(self.CodeS,["#AJOUT DES SUPPORTS"]) 

            if self.LesBi != []:
                CodeAppend(self.CodeS,["#AJOUT DES BUTEES SYMETRIQUES"])  
                for Bu in self.LesBi:
                    [A,P,Bi]=Bu
                    self.Ajouter_Bi(A,P,Bi)

            if self.LesSupports != []:            
                CodeAppend(self.CodeS,["#AJOUT DES SUPPORTS"]) 
                for Supp in self.LesSupports:
                    [Typ,A,nom,repere]=Supp
                    self.Ajouter_Support(Typ,A,nom,repere)




    #---------------------------------------------------------------------------
    def X___Traiter_SIF(self): 
        LesPt=self.DicP.keys()
        LesP=[]
        SIF0=1
        for p in LesPt:
            SIF=self.DicP[p][6]
            if SIF==SIF0: 
                LesP.append(p)
            else:
                if LesP!=[]:
                    tex=""
                    nc=0
                    LTex=[]
                    LTex.extend([
                    "_F(",
                    "   GROUP_NO=(",
                    ])
                    for m in LesP :
                        nc+=len(m)+4       
                        tex += "'"+m+"', "
                        if nc > 40:
                            LTex.append("       "+tex)
                            tex=""
                            nc=0
                    LTex.extend([
                    "       "+tex,
                    "   ),",
                    "   NOM_CMP='TEMP',",
                    "   VALE="+str(SIF0)+",",          
                    "),",
                    ])
                    
                    Lx =  TrouverLigne(self.CodeA,"#CHAMP_SIF")
                    CodeInsertI(self.CodeA,Lx,2,LTex)   
                    LesP=[]
                
                LesP.append(p)
                SIF0=SIF
                
        if LesP!=[]:
            tex=""
            nc=0
            LTex=[]
            LTex.extend([
            "_F(",
            "   GROUP_NO=(",
            ])
            for m in LesP :
                nc+=len(m)+4       
                tex += "'"+m+"', "
                if nc > 40:
                    LTex.append("       "+tex)
                    tex=""
                    nc=0
            LTex.extend([
            "       "+tex,
            "   ),",
            "   NOM_CMP='TEMP',",
            "   VALE="+str(SIF0)+",",          
            "),",
            ])
            
            Lx =  TrouverLigne(self.CodeA,"#CHAMP_SIF")
            CodeInsertI(self.CodeA,Lx,2,LTex)  
            

        

    #---------------------------------------------------------------------------
    #---------------------------------------------------------------------------
                    


    #---------------------------------------------------------------------------
    def X__EcrireFichiers(self):
        
        AfficherTitre(1,"Enregistrements")
        
        CodeInsert(self.CodeS,0,[
        "#!/usr/bin/python 3",
        "# -*- coding: iso-8859-1 -*-",
        "",
        "import time",
        "time1=time.time()",
        "import sys",
        "sys.path.append('/home/scartek/Documents/SCARTEK/01-Outils/TUBA')",
        "sys.path.append('"+MonRepertoire+"')",
        "",
        "import salome",
        "import geompy",
        "import GEOM",
        "import math",
        "import smesh, SALOMEDS, SMESH",
        "import StdMeshers",	
        "import NETGENPlugin",
        "gg = salome.ImportComponentGUI(\"GEOM\")",

        
        # Définition des éléments du repère principal

        "O = geompy.MakeVertex(0,0,0)",
        "O_id = geompy.addToStudy(O,\"O\")",

        "Vx= geompy.MakeVectorDXDYDZ(1,0,0)",
        "geompy.addToStudy(Vx,\"Vx\")",
        
        "Vy= geompy.MakeVectorDXDYDZ(0,1,0)",
        "geompy.addToStudy(Vy,\"Vy\")",
        
        "Vz= geompy.MakeVectorDXDYDZ(0,0,1)",
        "geompy.addToStudy(Vz,\"Vz\")",

        # Listes d'élément à ajouter à l'étude
        
        "Liste=[]",
        "L1=[]",
        "L2=[]",
        "List_id=[]",
        "ERREUR=False",
        ]),
        
        CodeAppend(self.CodeS,[ 
        "if salome.sg.hasDesktop():",
        "    salome.sg.updateObjBrowser(0)",
        "time2=time.time()",
        "dtime = time2 - time1",
        "print(\"------------------------\")",
        "print(\"Duree de la construction:\"+str(round(dtime,2))+\"s\")",
        ])
        
        f = open(fichier_py,'w')
        for t in self.CodeS:
            t = t+"\n"
            f.write(t)
        f.close()
            
        # Ecriture du CodeA dans le fichier 
        f=open(fichier_comm,'w')
        for t in self.CodeA:
            t = t+"\n"
            f.write(t)
        f.close()



#-------------------------------------------------------------------------------
def X___Main():

    a = Test()	
    
    a.X__LireFichiers()
    a.X__SimplifierCode()
    a.X__TransformerVariables()
    a.X__ConvertirWire()
    a.X__TransformerBoucles() 
    a.X__VerifierCode_1()
    a.X__EvaluerFormules()
    a.X__VerifierCode_2()
    a.X__VerifierCoherence()
    a.X__ConvertirCode_1()
    a.X__ConvertirCode_2()
    a.X__TraiterCode()
    a.X__EcrireFichiers()
    
    print
    print
    print("------------------------")
    print("         OK")
    print("------------------------")
    print

#-------------------------------------------------------------------------------

X___Main()


